ó àtÚ_c@sddZddlmZddlmZddlmZdZd%Zdd&Z d e fd „ƒYZ d e fd „ƒYZ de fd„ƒYZ de fd„ƒYZde fd„ƒYZde fd„ƒYZdefd„ƒYZdd„Zdefd„ƒYZdefd„ƒYZdefd„ƒYZd efd!„ƒYZd"efd#„ƒYZd$S('sBinary Event Stream Decoding iÿÿÿÿ(tcrc32(tunpack(tEventStreamErrori i€iiit ParserErrorcBseZdZRS(s.Base binary flow encoding parsing exception. (t__name__t __module__t__doc__(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRstDuplicateHeadercBseZdZd„ZRS(s%Duplicate header found in the event. cCs$d|}tt|ƒj|ƒdS(NsDuplicate header present: "%s"(tsuperRt__init__(tselftheadertmessage((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR s (RRRR (((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRstInvalidHeadersLengthcBseZdZd„ZRS(s+Headers length is longer than the maximum. cCs*d|tf}tt|ƒj|ƒdS(Ns.Header length of %s exceeded the maximum of %s(t_MAX_HEADERS_LENGTHRR R (R tlengthR ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR 's (RRRR (((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR %stInvalidPayloadLengthcBseZdZd„ZRS(s+Payload length is longer than the maximum. cCs*d|tf}tt|ƒj|ƒdS(Ns/Payload length of %s exceeded the maximum of %s(t_MAX_PAYLOAD_LENGTHRRR (R RR ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR 0s (RRRR (((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR.stChecksumMismatchcBseZdZd„ZRS(s9Calculated checksum did not match the expected checksum. cCs*d||f}tt|ƒj|ƒdS(Ns5Checksum mismatch: expected 0x%08x, calculated 0x%08x(RRR (R texpectedt calculatedR ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR 9s (RRRR (((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR7stNoInitialResponseErrorcBseZdZd„ZRS(sÊ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. cCs d}tt|ƒj|ƒdS(Ns0First event was not of the initial-response type(RRR (R R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR Fs(RRRR (((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR@st DecodeUtilscBseZdZdZdZdZdZdZdZdZ dZ ied 6ed 6ed 6Z e d „ƒZ e d „ƒZe d„ƒZe d„ƒZe d„ƒZe d„ƒZe d„ƒZe d„ƒZe d d„ƒZe d d„ƒZe d„ƒZe d„ƒZRS(sà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. s!Bs!Hs!Is!bs!hs!is!qs!IIIiiicCs tdfS(s 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) i(tTrue(tdata((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_truecs cCs tdfS(sThis 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) i(tFalse(R((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_falseps cCs$ttj|d ƒd}|dfS(sí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) ii(RRtUINT8_BYTE_FORMAT(Rtvalue((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_uint8}s cCs$ttj|d ƒd}|dfS(sî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) ii(RRtUINT32_BYTE_FORMAT(RR((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_uint32Šs cCs$ttj|d ƒd}|dfS(sê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) ii(RRtINT8_BYTE_FORMAT(RR((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_int8—s cCs$ttj|d ƒd}|dfS(sParse 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) ii(RRtINT16_BYTE_FORMAT(RR((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_int16¤s cCs$ttj|d ƒd}|dfS(sParse 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) ii(RRtINT32_BYTE_FORMAT(RR((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_int32²s cCs$ttj|d ƒd}|dfS(sParse 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) ii(RRtINT64_BYTE_FORMAT(RR((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_int64Às cCsEtj|}t||| ƒd}||}|||!}||fS(s¤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 preceeding 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). i(RtUINT_BYTE_FORMATR(Rtlength_byte_sizetuint_byte_formatRt bytes_endt array_bytes((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytunpack_byte_arrayÎs    cCs+tj||ƒ\}}|jdƒ|fS(sÙ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 preceeding 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). sutf-8(RR.tdecode(RR*R-tconsumed((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytunpack_utf8_stringçscCs|d dfS(sÛ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). i((R((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt unpack_uuidÿs cCsttj|ƒtfS(s…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) (RRtPRELUDE_BYTE_FORMATt_PRELUDE_LENGTH(R((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytunpack_prelude s (RRRRtUINT16_BYTE_FORMATRR!R#R%R'R3R)t staticmethodRRRR R"R$R&R(R.R1R2R5(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRKs6       icCs5t||ƒd@}||kr1t||ƒ‚ndS(NIÿÿÿÿ(RR(Rtchecksumtcrctcomputed_checksum((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_validate_checksums tMessagePreludecBsDeZdZd„Zed„ƒZed„ƒZed„ƒZRS(s3Represents the prelude of an event stream message. cCs||_||_||_dS(N(t total_lengththeaders_lengthR9(R R=R>R9((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR $s  cCs|j|jtdS(s§Calculates the total payload length. The extra minus 4 bytes is for the message CRC. :rtype: int :returns: The total payload length. i(R=R>R4(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytpayload_length)s cCs |jdS(s 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. i(R=(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt payload_end4s cCs t|jS(sÐ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. (R4R>(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt headers_end@s(RRRR tpropertyR?R@RA(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR<"s    tEventStreamMessagecBs#eZdZd„Zdd„ZRS(s$Represents an event stream message. cCs(||_||_||_||_dS(N(tpreludetheaderstpayloadR9(R RDRERFR9((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR Ms   iÈcCsR|jjdƒ}|dks*|dkr3d}ni|d6|jd6|jd6S(Ns :message-typeterrort exceptionit status_codeREtbody(REtgetRF(R RIt message_type((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytto_response_dictSs  (RRRR RM(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRCKs tEventStreamHeaderParsercBsÀeZdZi ejd6ejd6ejd6ejd6ejd6ej d6ej d6ej d6ej d 6ej d 6Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„ZRS(s Parses 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. iiiiiiiiii cCs d|_dS(N(tNonet_data(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR scCs||_|jƒS(sParses 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 dicionary of header key, value pairs. (RPt_parse_headers(R R((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytparse‚s cCsQi}xD|jrL|jƒ\}}||kr?t|ƒ‚n|||RR R?RR(R RD((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_validate_preludeÆscCsW|jt }tj|ƒ\}}t|Œ}|j|ƒt|td |jƒ|S(Ni(RPR4RR5R<RbR;R9(R t prelude_bytest raw_preludet_RD((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_parse_preludeÍs    cCs&|jt|jj!}|jj|ƒS(N(RPR4R_RAR`RR(R t header_bytes((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRQÖscCs#|j}|j|j|j!}|S(N(R_RPRAR@(R RDt payload_bytes((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_parse_payloadÚs cCs8|j}|j|j|j!}tj|ƒ\}}|S(N(R_RPR@R=RR (R RDt crc_bytest message_crcRe((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_parse_message_crcßs cCs|jtd|jj!}|S(Ni(RPR4R_R@(R t message_bytes((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_parse_message_bytesåscCs5|jƒ}|jƒ}t||d|jjƒ|S(NR9(RlRnR;R_R9(R RkRm((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_validate_message_crcês  cCsJ|jƒ}|jƒ}|jƒ}t|j|||ƒ}|jƒ|S(N(RoRQRiRCR_t_prepare_for_next_message(R R9RERFR ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt_parse_messageðs     cCs#|j|jj|_d|_dS(N(RPR_R=RO(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRpøscCsst|jƒtkr!tƒ‚n|jdkrB|jƒ|_nt|jƒ|jjkritƒ‚n|jƒS(s—Provides the next available message parsed from the stream :rtype: EventStreamMessage :returns: The next event stream message N( tlenRPR4t StopIterationR_RORfR=Rq(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytnextýs  cCs |jƒS(N(Rt(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt__next__scCs|S(N((R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt__iter__s(RRRR RaRbRfRQRiRlRnRoRqRpRtRuRv(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR]²s            t EventStreamcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sÐ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.") cCs7||_||_||_||_|jƒ|_dS(N(t _raw_streamt _output_shapet_operation_namet_parsert_create_raw_event_generatort_event_generator(R t raw_streamt output_shapetparsertoperation_name((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR @s     ccs5x.|jD]#}|j|ƒ}|r |Vq q WdS(N(R}t _parse_event(R teventt parsed_event((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRvGsccsJtƒ}x:|jjƒD])}|j|ƒx|D] }|Vq3WqWdS(N(R]RxtstreamRa(R tevent_stream_buffertchunkRƒ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR|Ms    cCsN|jƒ}|jj||jƒ}|ddkr8|St||jƒ‚dS(NRIiÈ(RMR{RRRyRRz(R Rƒt response_dicttparsed_response((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyR‚Ts  cCsVy5t|jƒ}|jjdƒ}|dkr4|SWntk rHnXtƒ‚dS(Ns :event-typesinitial-response(RtR}RERKRsR(R t initial_eventt event_type((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pytget_initial_response\s  cCs|jjƒdS(s&Closes the underlying streaming body. N(Rxtclose(R ((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRfs( RRRR RvR|R‚RŒR(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyRws*     Nii(RtbinasciiRtstructRtbotocore.exceptionsRR4RRt ExceptionRRR RRRtobjectRR;R<RCRNR]Rw(((s?/opt/awscli/lib/python2.7/site-packages/botocore/eventstream.pyt s&     Ï )Tc