o <&aE@sddlZddlmZddlmZmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZeeZGd d d eZd d ZdS)N)set_socket_timeout)IncompleteReadErrorReadTimeoutErrorResponseStreamingError)r) ProtocolError)parsers) ScalarTypes) XMLParseError)first_non_none_responsec@sheZdZdZdZddZddZddd Zd d Zd d Z e Z dddZ efddZ ddZ ddZdS) StreamingBodyaeWrapper class for an http response body. This provides a few additional conveniences that do not exist in the urllib3 model: * Set the timeout on the socket (i.e read() timeouts) * Auto validation of content length, if the amount of bytes we read does not match the content length, an exception is raised. cCs||_||_d|_dS)Nr) _raw_stream_content_length _amount_read)self raw_streamcontent_lengthr3/usr/lib/python3/dist-packages/botocore/response.py__init__0s zStreamingBody.__init__cCs2z t|j|WdStytjdddw)z&Set the timeout seconds on the socket.zbCannot access the socket object of a streaming response. It's possible the interface has changed.T)exc_infoN)rr AttributeErrorloggererror)rtimeoutrrrr5s  z StreamingBody.set_socket_timeoutNc Csz|j|}Wn#ty}zt|j|dd}~wty+}zt|dd}~ww|jt|7_|dus?|sC|dkrC| |S)zhRead at most amt bytes from the stream. If the amt argument is omitted, read all data. ) endpoint_urlrN)rr) r readURLLib3ReadTimeoutErrorrurlURLLib3ProtocolErrorrrlen_verify_content_length)ramtchunkerrrrLs zStreamingBody.readcCs ||jS)zCReturn an iterator to yield 1k chunks from the raw stream. ) iter_chunks_DEFAULT_CHUNK_SIZErrrr__iter__`s zStreamingBody.__iter__cCs||j}|r |St)z6Return the next 1k chunk from the raw stream. )rr& StopIteration)r current_chunkrrr__next__es zStreamingBody.__next__Fccsjd}||D]}||d}|ddD] }||dVq|d}q|r3||dVdSdS)zReturn an iterator to yield lines from the raw stream. This is achieved by reading chunk of bytes (of size chunk_size) at a time from the raw stream, and then yielding lines from there. TNr)r% splitlines)r chunk_sizekeependspendingr#lineslinerrr iter_linesos zStreamingBody.iter_linesccs" ||}|dkr dS|Vq)z\Return an iterator to yield chunks of chunk_size bytes from the raw stream. Tr,N)r)rr/r*rrrr%~s zStreamingBody.iter_chunkscCs6|jdur|jt|jkrt|jt|jddSdS)N) actual_bytesexpected_bytes)rrintrr'rrrr!s z$StreamingBody._verify_content_lengthcCs|jdS)z*Close the underlying http response stream.N)r closer'rrrr8szStreamingBody.close)N)r F)__name__ __module__ __qualname____doc__r&rrrr(r+nextr4r%r!r8rrrrr "s     r cCsx|jd}|j|jd}|ddkr|j|d<n|jr)t|j|dd|d<n|j|d<t |}|| ||j fS)Nprotocol)headers status_coder@i,bodyr?zcontent-length) metadatar?r@contenthas_streaming_outputr rawgetr create_parserparse output_shape)operation_model http_responser> response_dictparserrrr get_responses     rN)loggingbotocore.compatrbotocore.exceptionsrrrurllib3.exceptionsrrrbotocorerrr botocore.hooksr getLoggerr9robjectr rNrrrrs         u