HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/site-packages/botocore/__pycache__/eventstream.cpython-38.pyc
U

KD�gO�@s�dZddlmZddlmZddlmZdZdZGdd�de	�Z
Gd	d
�d
e
�ZGdd�de
�ZGd
d�de
�Z
Gdd�de
�ZGdd�de
�ZGdd�d�Zd"dd�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd �d �Zd!S)#zBinary Event Stream Decoding�)�crc32)�unpack)�EventStreamError�ic@seZdZdZdS)�ParserErrorz,Base binary flow encoding parsing exception.N)�__name__�
__module__�__qualname__�__doc__�rr�A/opt/cppython/lib/python3.8/site-packages/botocore/eventstream.pyrsrcs eZdZdZ�fdd�Z�ZS)�DuplicateHeaderz$Duplicate header found in the event.csd|�d�}t��|�dS)NzDuplicate header present: "�"��super�__init__)�self�header�message��	__class__rrr"szDuplicateHeader.__init__�rrr	r
r�
__classcell__rrrrr
sr
cs eZdZdZ�fdd�Z�ZS)�InvalidHeadersLengthz*Headers length is longer than the maximum.cs d|�dt��}t��|�dS)NzHeader length of z exceeded the maximum of )�_MAX_HEADERS_LENGTHrr�r�lengthrrrrr*szInvalidHeadersLength.__init__rrrrrr'srcs eZdZdZ�fdd�Z�ZS)�InvalidPayloadLengthz�Payload length is longer than the maximum.

    DEPRECATED: This case is no longer validated client side. Payloads
    of varying lengths are now supported by AWS services.
    csd|�d�}t��|�dS)NzPayload length of z exceeded the maximum of 24MB.rrrrrr6szInvalidPayloadLength.__init__rrrrrr/srcs eZdZdZ�fdd�Z�ZS)�ChecksumMismatchz8Calculated checksum did not match the expected checksum.cs$d|d�d|d��}t��|�dS)NzChecksum mismatch: expected 0x�08xz, calculated 0xr)r�expectedZ
calculatedrrrrr>szChecksumMismatch.__init__rrrrrr;srcs eZdZdZ�fdd�Z�ZS)�NoInitialResponseErrorz�An event of type initial-response was not received.

    This exception is raised when the event stream produced no events or
    the first event in the stream was not of the initial-response type.
    csd}t��|�dS)Nz0First event was not of the initial-response typer)rrrrrrJszNoInitialResponseError.__init__rrrrrr!Csr!c@s�eZdZdZdZdZdZdZdZdZ	dZ
d	Zeeed
�Ze
dd��Ze
d
d��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Ze
d%dd��Ze
d&dd��Ze
d d!��Ze
d"d#��Zd$S)'�DecodeUtilsz�Unpacking utility functions used in the decoder.

    All methods on this class take raw bytes and return  a tuple containing
    the value parsed from the bytes and the number of bytes consumed to parse
    that value.
    z!Bz!Hz!Iz!bz!hz!iz!qz!III)���cCsdS)aThis method consumes none of the provided bytes and returns True.

        :type data: bytes
        :param data: The bytes to parse from. This is ignored in this method.

        :rtype: tuple
        :rtype: (bool, int)
        :returns: The tuple (True, 0)
        )Trr��datarrr�unpack_truegszDecodeUtils.unpack_truecCsdS)aThis method consumes none of the provided bytes and returns False.

        :type data: bytes
        :param data: The bytes to parse from. This is ignored in this method.

        :rtype: tuple
        :rtype: (bool, int)
        :returns: The tuple (False, 0)
        )Frrr&rrr�unpack_falsetszDecodeUtils.unpack_falsecCs ttj|dd��d}|dfS)z�Parse an unsigned 8-bit integer from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: (int, int)
        :returns: A tuple containing the (parsed integer value, bytes consumed)
        Nr#r)rr"�UINT8_BYTE_FORMAT�r'�valuerrr�unpack_uint8�s
zDecodeUtils.unpack_uint8cCs ttj|dd��d}|dfS)z�Parse an unsigned 32-bit integer from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: (int, int)
        :returns: A tuple containing the (parsed integer value, bytes consumed)
        Nr%r)rr"�UINT32_BYTE_FORMATr+rrr�
unpack_uint32�s
zDecodeUtils.unpack_uint32cCs ttj|dd��d}|dfS)z�Parse a signed 8-bit integer from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: (int, int)
        :returns: A tuple containing the (parsed integer value, bytes consumed)
        Nr#r)rr"�INT8_BYTE_FORMATr+rrr�unpack_int8�s
zDecodeUtils.unpack_int8cCs ttj|dd��d}|dfS)aParse a signed 16-bit integer from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: tuple
        :rtype: (int, int)
        :returns: A tuple containing the (parsed integer value, bytes consumed)
        Nr$r)rr"�INT16_BYTE_FORMATr+rrr�unpack_int16�szDecodeUtils.unpack_int16cCs ttj|dd��d}|dfS)aParse a signed 32-bit integer from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: tuple
        :rtype: (int, int)
        :returns: A tuple containing the (parsed integer value, bytes consumed)
        Nr%r)rr"�INT32_BYTE_FORMATr+rrr�unpack_int32�szDecodeUtils.unpack_int32cCs ttj|dd��d}|dfS)aParse a signed 64-bit integer from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: tuple
        :rtype: (int, int)
        :returns: A tuple containing the (parsed integer value, bytes consumed)
        N�r)rr"�INT64_BYTE_FORMATr+rrr�unpack_int64�szDecodeUtils.unpack_int64r$cCs<tj|}t||d|��d}||}|||�}||fS)a�Parse a variable length byte array from the bytes.

        The bytes are expected to be in the following format:
            [ length ][0 ... length bytes]
        where length is an unsigned integer represented in the smallest number
        of bytes to hold the maximum length of the array.

        :type data: bytes
        :param data: The bytes to parse from.

        :type length_byte_size: int
        :param length_byte_size: The byte size of the preceding integer that
        represents the length of the array. Supported values are 1, 2, and 4.

        :rtype: (bytes, int)
        :returns: A tuple containing the (parsed byte array, bytes consumed).
        Nr)r"�UINT_BYTE_FORMATr)r'�length_byte_sizeZuint_byte_formatrZ	bytes_end�array_bytesrrr�unpack_byte_array�s

zDecodeUtils.unpack_byte_arraycCst�||�\}}|�d�|fS)a�Parse a variable length utf-8 string from the bytes.

        The bytes are expected to be in the following format:
            [ length ][0 ... length bytes]
        where length is an unsigned integer represented in the smallest number
        of bytes to hold the maximum length of the array and the following
        bytes are a valid utf-8 string.

        :type data: bytes
        :param bytes: The bytes to parse from.

        :type length_byte_size: int
        :param length_byte_size: The byte size of the preceding integer that
        represents the length of the array. Supported values are 1, 2, and 4.

        :rtype: (str, int)
        :returns: A tuple containing the (utf-8 string, bytes consumed).
        zutf-8)r"r<�decode)r'r:r;�consumedrrr�unpack_utf8_string�s
�zDecodeUtils.unpack_utf8_stringcCs|dd�dfS)z�Parse a 16-byte uuid from the bytes.

        :type data: bytes
        :param data: The bytes to parse from.

        :rtype: (bytes, int)
        :returns: A tuple containing the (uuid bytes, bytes consumed).
        N�rr&rrr�unpack_uuids
zDecodeUtils.unpack_uuidcCsttj|�tfS)a�Parse the prelude for an event stream message from the bytes.

        The prelude for an event stream message has the following format:
            [total_length][header_length][prelude_crc]
        where each field is an unsigned 32-bit integer.

        :rtype: ((int, int, int), int)
        :returns: A tuple of ((total_length, headers_length, prelude_crc),
        consumed)
        )rr"�PRELUDE_BYTE_FORMAT�_PRELUDE_LENGTHr&rrr�unpack_preludeszDecodeUtils.unpack_preludeN)r$)r$)rrr	r
r*ZUINT16_BYTE_FORMATr.r0r2r4r7rBr9�staticmethodr(r)r-r/r1r3r5r8r<r?rArDrrrrr"OsJ�











r"cCs$t||�d@}||kr t||��dS)Nl��)rr)r'Zchecksum�crcZcomputed_checksumrrr�_validate_checksumsrGc@s<eZdZdZdd�Zedd��Zedd��Zedd	��Zd
S)�MessagePreludez2Represents the prelude of an event stream message.cCs||_||_||_dS�N)�total_length�headers_lengthrF)rrJrKrFrrrr*szMessagePrelude.__init__cCs|j|jtdS)z�Calculates the total payload length.

        The extra minus 4 bytes is for the message CRC.

        :rtype: int
        :returns: The total payload length.
        r%)rJrKrC�rrrr�payload_length/s	zMessagePrelude.payload_lengthcCs
|jdS)a	Calculates the byte offset for the end of the message payload.

        The extra minus 4 bytes is for the message CRC.

        :rtype: int
        :returns: The byte offset from the beginning of the event stream
        message to the end of the payload.
        r%)rJrLrrr�payload_end:s
zMessagePrelude.payload_endcCs
t|jS)z�Calculates the byte offset for the end of the message headers.

        :rtype: int
        :returns: The byte offset from the beginning of the event stream
        message to the end of the headers.
        )rCrKrLrrr�headers_endFszMessagePrelude.headers_endN)	rrr	r
r�propertyrMrNrOrrrrrH's


rHc@s"eZdZdZdd�Zddd�ZdS)	�EventStreamMessagez#Represents an event stream message.cCs||_||_||_||_dSrI)�prelude�headers�payloadrF)rrRrSrTrFrrrrTszEventStreamMessage.__init__��cCs0|j�d�}|dks|dkr d}||j|jd�S)Nz
:message-type�error�	exceptioni�)�status_coderS�body)rS�getrT)rrXZmessage_typerrr�to_response_dictZs�z#EventStreamMessage.to_response_dictN)rU)rrr	r
rr[rrrrrQQsrQc@s~eZdZdZejejejejej	ej
ejejej
ej
d�
Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�ZdS)�EventStreamHeaderParseraParses the event headers from an event stream message.

    Expects all of the header data upfront and creates a dictionary of headers
    to return. This object can be reused multiple times to parse the headers
    from multiple event stream messages.
    )
rr#r$�r%���r6�	cCs
d|_dSrI��_datarLrrrr�sz EventStreamHeaderParser.__init__cCs||_|��S)aParses the event stream headers from an event stream message.

        :type data: bytes
        :param data: The bytes that correspond to the headers section of an
        event stream message.

        :rtype: dict
        :returns: A dictionary of header key, value pairs.
        )rc�_parse_headers�rr'rrr�parse�s
zEventStreamHeaderParser.parsecCs4i}|jr0|��\}}||kr&t|��|||<q|SrI)rc�
_parse_headerr
)rrS�namer,rrrrd�s
z&EventStreamHeaderParser._parse_headerscCs|��}|��}||fSrI)�_parse_name�_parse_value)rrhr,rrrrg�sz%EventStreamHeaderParser._parse_headercCs t�|jd�\}}|�|�|S)Nr#)r"r?rc�
_advance_data)rrhr>rrrri�s
z#EventStreamHeaderParser._parse_namecCst�|j�\}}|�|�|SrI)r"r-rcrk)r�typer>rrr�_parse_type�s
z#EventStreamHeaderParser._parse_typecCs.|��}|j|}||j�\}}|�|�|SrI)rm�_HEADER_TYPE_MAPrcrk)rZheader_typeZvalue_unpackerr,r>rrrrj�s


z$EventStreamHeaderParser._parse_valuecCs|j|d�|_dSrIrb)rr>rrrrk�sz%EventStreamHeaderParser._advance_dataN)rrr	r
r"r(r)r1r3r5r8r<r?rArnrrfrdrgrirmrjrkrrrrr\es(�
	r\c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�EventStreamBufferz�Streaming based event stream buffer

    A buffer class that wraps bytes from an event stream providing parsed
    messages as they become available via an iterable interface.
    cCsd|_d|_t�|_dS)N�)rc�_preluder\�_header_parserrLrrrr�szEventStreamBuffer.__init__cCs|j|7_dS)z�Add data to the buffer.

        :type data: bytes
        :param data: The bytes to add to the buffer to be used when parsing
        Nrbrerrr�add_data�szEventStreamBuffer.add_datacCs|jtkrt|j��dSrI)rKrr)rrRrrr�_validate_prelude�s
z#EventStreamBuffer._validate_preludecCsJ|jdt�}t�|�\}}t|�}t|dtd�|j�|�|�|S�Nr%)rcrCr"rDrHrGrFrt)rZ
prelude_bytesZraw_prelude�_rRrrr�_parse_prelude�s
z EventStreamBuffer._parse_preludecCs|jt|jj�}|j�|�SrI)rcrCrqrOrrrf)r�header_bytesrrrrd�sz EventStreamBuffer._parse_headerscCs|j}|j|j|j�}|SrI)rqrcrOrN)rrRZ
payload_bytesrrr�_parse_payload�sz EventStreamBuffer._parse_payloadcCs*|j}|j|j|j�}t�|�\}}|SrI)rqrcrNrJr"r/)rrRZ	crc_bytes�message_crcrvrrr�_parse_message_crc�sz$EventStreamBuffer._parse_message_crccCs|jtd|jj�}|Sru)rcrCrqrN)r�
message_bytesrrr�_parse_message_bytes�s
�z&EventStreamBuffer._parse_message_bytescCs&|��}|��}t|||jjd�|S)N)rF)r{r}rGrqrF)rrzr|rrr�_validate_message_crc�sz'EventStreamBuffer._validate_message_crccCs4|��}|��}|��}t|j|||�}|��|SrI)r~rdryrQrq�_prepare_for_next_message)rrFrSrTrrrr�_parse_message�sz EventStreamBuffer._parse_messagecCs|j|jjd�|_d|_dSrI)rcrqrJrLrrrr�sz+EventStreamBuffer._prepare_for_next_messagecCsHt|j�tkrt��|jdkr(|��|_t|j�|jjkr@t��|��S)z�Provides the next available message parsed from the stream

        :rtype: EventStreamMessage
        :returns: The next event stream message
        N)�lenrcrC�
StopIterationrqrwrJr�rLrrr�nexts

zEventStreamBuffer.nextcCs|��SrI)r�rLrrr�__next__szEventStreamBuffer.__next__cCs|SrIrrLrrr�__iter__szEventStreamBuffer.__iter__N)rrr	r
rrsrtrwrdryr{r}r~r�rr�r�r�rrrrro�s	roc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�EventStreama�Wrapper class for an event stream body.

    This wraps the underlying streaming body, parsing it for individual events
    and yielding them as they come available through the iterator interface.

    The following example uses the S3 select API to get structured data out of
    an object stored in S3 using an event stream.

    **Example:**
    ::
        from botocore.session import Session

        s3 = Session().create_client('s3')
        response = s3.select_object_content(
            Bucket='bucketname',
            Key='keyname',
            ExpressionType='SQL',
            RequestProgress={'Enabled': True},
            Expression="SELECT * FROM S3Object s",
            InputSerialization={'CSV': {}},
            OutputSerialization={'CSV': {}},
        )
        # This is the event stream in the response
        event_stream = response['Payload']
        end_event_received = False
        with open('output', 'wb') as f:
            # Iterate over events in the event stream as they come
            for event in event_stream:
                # If we received a records event, write the data to a file
                if 'Records' in event:
                    data = event['Records']['Payload']
                    f.write(data)
                # If we received a progress event, print the details
                elif 'Progress' in event:
                    print(event['Progress']['Details'])
                # End event indicates that the request finished successfully
                elif 'End' in event:
                    print('Result is complete')
                    end_event_received = True
        if not end_event_received:
            raise Exception("End event not received, request incomplete.")
    cCs&||_||_||_||_|��|_dSrI)�_raw_stream�
_output_shape�_operation_name�_parser�_create_raw_event_generator�_event_generator)rZ
raw_streamZoutput_shape�parserZoperation_namerrrrGs
zEventStream.__init__ccs$|jD]}|�|�}|r|VqdSrI)r��_parse_event)r�eventZparsed_eventrrrr�Ns

zEventStream.__iter__ccs.t�}|j��D]}|�|�|EdHqdSrI)ror��streamrs)rZevent_stream_buffer�chunkrrrr�Ts
z'EventStream._create_raw_event_generatorcCs8|��}|j�||j�}|ddkr(|St||j��dS)NrXrU)r[r�rfr�rr�)rr�Z
response_dictZparsed_responserrrr�Zs
zEventStream._parse_eventcCsHz(t|j�}|j�d�}|dkr&|WSWntk
r<YnXt��dS)Nz:event-typezinitial-response)r�r�rSrZr�r!)rZ
initial_eventZ
event_typerrr�get_initial_responsebs

z EventStream.get_initial_responsecCs|j��dS)z%Closes the underlying streaming body.N)r��closerLrrrr�lszEventStream.closeN)
rrr	r
rr�r�r�r�r�rrrrr�s+
r�N)r)r
�binasciir�structrZbotocore.exceptionsrrCr�	Exceptionrr
rrrr!r"rGrHrQr\ror�rrrr�<module>
s&Q
*Tb