File: //opt/alt/python311/lib/python3.11/site-packages/botocore/__pycache__/parsers.cpython-311.pyc
�
/�;f'� � �6 � d Z ddlZddlZddlZddlZddlZddlmZm Z ddl
mZmZ ddl
mZmZmZmZ ej e� � ZeZ G d� d� � Zd� Zd � Z G d
� de� � Z G d� d
� � Z G d� de� � Z G d� de� � Z G d� de� � Z G d� de� � Z G d� de� � Z G d� de e� � Z! G d� de e� � Z" G d� de� � Z# G d� de� � Z$ G d � d!e$e� � Z% G d"� d#e$e� � Z&eee#e%e&d$�Z'dS )%a� Response parsers for the various protocol types.
The module contains classes that can take an HTTP response, and given
an output shape, parse the response into a dict according to the
rules in the output shape.
There are many similarities amongst the different protocols with regard
to response parsing, and the code is structured in a way to avoid
code duplication when possible. The diagram below is a diagram
showing the inheritance hierarchy of the response classes.
::
+--------------+
|ResponseParser|
+--------------+
^ ^ ^
+--------------------+ | +-------------------+
| | |
+----------+----------+ +------+-------+ +-------+------+
|BaseXMLResponseParser| |BaseRestParser| |BaseJSONParser|
+---------------------+ +--------------+ +--------------+
^ ^ ^ ^ ^ ^
| | | | | |
| | | | | |
| ++----------+-+ +-+-----------++ |
| |RestXMLParser| |RestJSONParser| |
+-----+-----+ +-------------+ +--------------+ +----+-----+
|QueryParser| |JSONParser|
+-----------+ +----------+
The diagram above shows that there is a base class, ``ResponseParser`` that
contains logic that is similar amongst all the different protocols (``query``,
``json``, ``rest-json``, ``rest-xml``). Amongst the various services there
is shared logic that can be grouped several ways:
* The ``query`` and ``rest-xml`` both have XML bodies that are parsed in the
same way.
* The ``json`` and ``rest-json`` protocols both have JSON bodies that are
parsed in the same way.
* The ``rest-json`` and ``rest-xml`` protocols have additional attributes
besides body parameters that are parsed the same (headers, query string,
status code).
This is reflected in the class diagram above. The ``BaseXMLResponseParser``
and the BaseJSONParser contain logic for parsing the XML/JSON body,
and the BaseRestParser contains logic for parsing out attributes that
come from other parts of the HTTP response. Classes like the
``RestXMLParser`` inherit from the ``BaseXMLResponseParser`` to get the
XML body parsing logic and the ``BaseRestParser`` to get the HTTP
header/status code/query string parsing.
Additionally, there are event stream parsers that are used by the other parsers
to wrap streaming bodies that represent a stream of events. The
BaseEventStreamParser extends from ResponseParser and defines the logic for
parsing values from the headers and payload of a message from the underlying
binary encoding protocol. Currently, event streams support parsing bodies
encoded as JSON and XML through the following hierarchy.
+--------------+
|ResponseParser|
+--------------+
^ ^ ^
+--------------------+ | +------------------+
| | |
+----------+----------+ +----------+----------+ +-------+------+
|BaseXMLResponseParser| |BaseEventStreamParser| |BaseJSONParser|
+---------------------+ +---------------------+ +--------------+
^ ^ ^ ^
| | | |
| | | |
+-+----------------+-+ +-+-----------------+-+
|EventStreamXMLParser| |EventStreamJSONParser|
+--------------------+ +---------------------+
Return Values
=============
Each call to ``parse()`` returns a dict has this form::
Standard Response
{
"ResponseMetadata": {"RequestId": <requestid>}
<response keys>
}
Error response
{
"ResponseMetadata": {"RequestId": <requestid>}
"Error": {
"Code": <string>,
"Message": <string>,
"Type": <string>,
<additional keys>
}
}
� N)�ETree�
XMLParseError)�EventStream�NoInitialResponseError)�is_json_value_header�lowercase_dict�merge_dicts�parse_timestampc � � e Zd Zd� Zd� Zd� ZdS )�ResponseParserFactoryc � � i | _ d S �N)� _defaults)�selfs �C/opt/alt/python311/lib/python3.11/site-packages/botocore/parsers.py�__init__zResponseParserFactory.__init__� s
� ������ c �: � | j � |� � dS )aO Set default arguments when a parser instance is created.
You can specify any kwargs that are allowed by a ResponseParser
class. There are currently two arguments:
* timestamp_parser - A callable that can parse a timestamp string
* blob_parser - A callable that can parse a blob type
N)r �update)r �kwargss r �set_parser_defaultsz)ResponseParserFactory.set_parser_defaults� s � �
����f�%�%�%�%�%r c �6 � t | } |di | j ��S )N� )�PROTOCOL_PARSERSr )r �
protocol_name�
parser_clss r �
create_parserz#ResponseParserFactory.create_parser� s$ � �%�m�4�
��z�+�+�D�N�+�+�+r N)�__name__�
__module__�__qualname__r r r r r r r r � sA � � � � � �� � �
&�
&�
&�,� ,� ,� ,� ,r r c �D � t � � � | � � S r )r r )�protocols r r r � s � � �"�"�0�0��:�:�:r c � � � � fd�}|S )Nc �Z �� t |d� � r|j }|�d}n|} �| ||� � S )N�text� )�hasattrr% )r �shape�node_or_stringr% �funcs �r �_get_text_contentz(_text_content.<locals>._get_text_content� sC �� ��>�6�*�*� "�!�&�D��|� ���!�D��t�D�%��&�&�&r r )r* r+ s ` r �
_text_contentr, � s$ �� �
'�
'�
'�
'�
'� �r c � � e Zd ZdS )�ResponseParserErrorN)r r r r r r r. r. � s � � � � � ��Dr r. c � � e Zd ZdZdZdZdd�Zd� Zd� Zd� Z d� Z
d � Zd
� Zd� Z
d� Zd
� Zd� Zd� Zd� Zd� Zd� Zd� Zd� ZdS )�ResponseParserao Base class for response parsing.
This class represents the interface that all ResponseParsers for the
various protocols must implement.
This class will take an HTTP response and a model shape and parse the
HTTP response into a dictionary.
There is a single public method exposed: ``parse``. See the ``parse``
docstring for more info.
zutf-8Nc � � |�t }|| _ |�| j }|| _ d | _ | j �| � ||� � | _ d S d S r )�DEFAULT_TIMESTAMP_PARSER�_timestamp_parser�_default_blob_parser�_blob_parser�_event_stream_parser�EVENT_STREAM_PARSER_CLS)r �timestamp_parser�blob_parsers r r zResponseParser.__init__� sh � ��#�7��!1������3�K�'���$(��!��'�3�(,�(D�(D� �+�)� )�D�%�%�%� 4�3r c �* � t j |� � S r )�base64� b64decode�r �values r r4 z#ResponseParser._default_blob_parser� s � � ���&�&�&r c � � t � d|d � � t � d|d � � |d dk ro| � |� � r| � |� � }nZ| � |� � r| � ||� � }|S | � ||� � }n| � ||� � }|r|j � d� � r|S t |t � � rV|� di � � }|d |d <