D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
lib
/
python3
/
dist-packages
/
botocore
/
__pycache__
/
Filename :
parsers.cpython-312.pyc
back
Copy
� P��e'� � �� � 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'y)%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� Zy)�ResponseParserFactoryc � � i | _ y �N)� _defaults)�selfs �2/usr/lib/python3/dist-packages/botocore/parsers.py�__init__zResponseParserFactory.__init__� s � ���� c �: � | j j |� y)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 �8 � t | } |di | j ��S )N� )�PROTOCOL_PARSERSr )r � protocol_name� parser_clss r � create_parserz#ResponseParserFactory.create_parser� s � �%�m�4� ��+�D�N�N�+�+r N)�__name__� __module__�__qualname__r r r r r r r r � s � �� &�,r r c �4 � t � j | � S r )r r )�protocols r r r � s � � �"�0�0��:�:r c � � � � fd�}|S )Nc �V �� 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� s8 �� ��>�6�*�!�&�&�D��|� ��!�D��D�%��&�&r r )r* r+ s ` r � _text_contentr, � s �� � '� �r c � � e Zd Zy)�ResponseParserErrorN)r r r r r r r. r. � s � �r r. c � � e Zd ZdZdZdZdd�Zd� Zd� Zd� Z d� Z d � Zd � Zd� Z d� Zd � Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zy)�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 �| j ||� | _ y y 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__� s` � ��#�7��!1������3�3�K�'���$(��!��'�'�3�(,�(D�(D� �+�)�D�%� 4r c �, � t j |� S r )�base64� b64decode�r �values r r4 z#ResponseParser._default_blob_parser� s � � ����&�&r c �: � t j d|d � t j d|d � |d dk\ r[| j |� r| j |� }nJ| j |� r| j ||� }|S | j ||� }n| j ||� }|r|j j d� r|S t |t � rD|j di � }|d |d <