B ㊇c;@sddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZddlmZdd l mZdd lmZeeZGd d d eZd dZdS)N)IOBase) ProtocolError)ReadTimeoutError)parsers)set_socket_timeout)IncompleteReadErrorrResponseStreamingError) ScalarTypes) XMLParseError)first_non_none_responsec@seZdZdZdZddZddZddZd d Zd#d d Z ddZ ddZ ddZ ddZ ddZe ZedfddZefddZddZdd Zd!d"Zd S)$ 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. icCs||_||_d|_dS)Nr) _raw_stream_content_length _amount_read)selfZ raw_streamcontent_lengthrl/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/botocore/response.py__init__5szStreamingBody.__init__cCsdS)Nr)rrrr__del__:szStreamingBody.__del__cCs:yt|j|Wn$tk r4tjdddYnXdS)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)rtimeoutrrrr@s z StreamingBody.set_socket_timeoutcCs$y |jStk rdSXdS)NF)r readabler)rrrrrWs zStreamingBody.readableNc Csy|j|}WnZtk r@}zt|j|dWdd}~XYn,tk rj}zt|dWdd}~XYnX|jt|7_|dks|s|dkr| |S)zhRead at most amt bytes from the stream. If the amt argument is omitted, read all data. )Z endpoint_urlrN)rr) r readURLLib3ReadTimeoutErrorrurlURLLib3ProtocolErrorrrlen_verify_content_length)ramtchunkerrrr]szStreamingBody.readcCs |jS)N)r readlines)rrrrr%qszStreamingBody.readlinescCs ||jS)z:Return an iterator to yield 1k chunks from the raw stream.) iter_chunks_DEFAULT_CHUNK_SIZE)rrrr__iter__tszStreamingBody.__iter__cCs||j}|r|StdS)z-Return the next 1k chunk from the raw stream.N)rr' StopIteration)r current_chunkrrr__next__xs zStreamingBody.__next__cCs|jS)N)r )rrrr __enter__szStreamingBody.__enter__cCs|jdS)N)r close)rtypevalue tracebackrrr__exit__szStreamingBody.__exit__Fccsld}xN||D]@}||d}x$|ddD]}||dVq0W|d}qW|rh||dVdS)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_liness zStreamingBody.iter_linesccs$x||}|dkrP|VqWdS)z\Return an iterator to yield chunks of chunk_size bytes from the raw stream. r2N)r)rr5r*rrrr&s  zStreamingBody.iter_chunkscCs2|jdk r.|jt|jkr.t|jt|jddS)N)Z actual_bytesZexpected_bytes)rrintr)rrrrr!s  z$StreamingBody._verify_content_lengthcCs |jS)N)r tell)rrrrr<szStreamingBody.tellcCs|jdS)z*Close the underlying http response stream.N)r r-)rrrrr-szStreamingBody.close)N)__name__ __module__ __qualname____doc__r'rrrrrr%r(r+r,r1nextr:r&r!r<r-rrrrr &s$    r cCsx|jd}|j|jd}|ddkr0|j|d<n,|jrRt|j|dd|d<n |j|d<t |}|| ||j fS)Nprotocol)headers status_coderDi,bodyrCzcontent-length) metadatarCrDcontentZhas_streaming_outputr rawgetrZ create_parserparseZ output_shape)Zoperation_model http_responserBZ response_dictparserrrr get_responses      rM)loggingiorZurllib3.exceptionsrrrrZbotocorerZbotocore.compatrZbotocore.exceptionsrrr r Zbotocore.hooksr getLoggerr=rr rMrrrrs