o ?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/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/response.py__init__5s zStreamingBody.__init__cCsdSNrrrrr__del__:szStreamingBody.__del__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)rtimeoutrrrr@s  z StreamingBody.set_socket_timeoutcCs"z|jWStyYdSw)NF)r readablerrrrrrWs   zStreamingBody.readableNc 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. )Z endpoint_urlrN)rr) r readURLLib3ReadTimeoutErrorrurlURLLib3ProtocolErrorrrlen_verify_content_length)ramtchunkerrrr]s zStreamingBody.readcC |jSr)r readlinesrrrrr(q zStreamingBody.readlinescCs ||jS)z:Return an iterator to yield 1k chunks from the raw stream.) iter_chunks_DEFAULT_CHUNK_SIZErrrr__iter__ts zStreamingBody.__iter__cCs||j}|r |St)z-Return the next 1k chunk from the raw stream.)rr+ StopIteration)r current_chunkrrr__next__xs zStreamingBody.__next__cCs|jSr)r rrrr __enter__szStreamingBody.__enter__cCs|jdSrr close)rtypevalue tracebackrrr__exit__szStreamingBody.__exit__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_liness zStreamingBody.iter_linesccs" ||}|dkr dS|Vq)z\Return an iterator to yield chunks of chunk_size bytes from the raw stream. Tr7N)r)rr:r.rrrr*s zStreamingBody.iter_chunkscCs6|jdur|jt|jkrt|jt|jddSdS)N)Z actual_bytesZexpected_bytes)rrintrrrrrr#sz$StreamingBody._verify_content_lengthcCr'r)r tellrrrrrAr)zStreamingBody.tellcCs|jdS)z*Close the underlying http response stream.Nr1rrrrr2szStreamingBody.closer)__name__ __module__ __qualname____doc__r+rrrrrr(r,r/r0r6nextr?r*r#rAr2rrrrr &s&     r cCsx|jd}|j|jd}|ddkr|j|d<n|jr)t|j|dd|d<n|j|d<t |}|| ||j fS)Nprotocol)headers status_coderIi,bodyrHzcontent-length) metadatarHrIcontentZhas_streaming_outputr rawgetrZ create_parserparseZ output_shape)Zoperation_model http_responserGZ response_dictparserrrr get_responses     rR)loggingiorZurllib3.exceptionsrr!rrZbotocorerZbotocore.compatrZbotocore.exceptionsrrr r Zbotocore.hooksr getLoggerrBrr rRrrrrs