Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/botocore/__pycache__/parsers.cpython-39.pyc
Ðазад
a p�h=� � @ sz d Z ddlZddlZddlZddlZddlmZmZmZ ddl m Z mZ ddlm Z mZmZmZ e�e�Ze ZG dd� de�Zdd � Zd d� ZG dd � d e�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Z G dd� de e�Z!G dd� de e�Z"G dd� de�Z#G d d!� d!e�Z$G d"d#� d#e$e�Z%G d$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)�six�ETree� XMLParseError)�EventStream�NoInitialResponseError)�parse_timestamp�merge_dicts�is_json_value_header�lowercase_dictc @ s$ e Zd Zdd� Zdd� Zdd� ZdS )�ResponseParserFactoryc C s i | _ d S �N)� _defaults)�self� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/botocore/parsers.py�__init__� s zResponseParserFactory.__init__c K s | 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 timetsamp string * blob_parser - A callable that can parse a blob type N)r �update)r �kwargsr r r �set_parser_defaults� s z)ResponseParserFactory.set_parser_defaultsc C s t | }|f i | j��S r )�PROTOCOL_PARSERSr )r Z protocol_nameZ parser_clsr r r � create_parser� s z#ResponseParserFactory.create_parserN)�__name__� __module__�__qualname__r r r r r r r r � s r c C s t � �| �S r )r r )�protocolr r r r � s r c s � fdd�}|S )Nc s. t |d�r|j}|d u r"d}n|}� | ||�S )N�text� )�hasattrr )r �shape�node_or_stringr ��funcr r �_get_text_content� s z(_text_content.<locals>._get_text_contentr )r! r"