3 B\ @sddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl m Z mZddlmZddlmZejeZGdd d eZd d ZdS) N) ScalarTypes)first_non_none_response)jsonset_socket_timeout XMLParseError)IncompleteReadErrorReadTimeoutError)r)parsersc@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)selfZ raw_streamcontent_lengthrk/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/botocore/botocore/response.py__init__,szStreamingBody.__init__c Cs: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)rtimeoutrrrr1s z StreamingBody.set_socket_timeoutNcCsvy|jj|}Wn0tk r@}zt|j|dWYdd}~XnX|jt|7_|dksj| rr|dkrr|j|S)zhRead at most amt bytes from the stream. If the amt argument is omitted, read all data. )Z endpoint_urlrNr)r readURLLib3ReadTimeoutErrorrurlrlen_verify_content_length)ramtchunkerrrrHs zStreamingBody.readcCs |j|jS)zCReturn an iterator to yield 1k chunks from the raw stream. ) iter_chunks_DEFAULT_CHUNK_SIZE)rrrr__iter__ZszStreamingBody.__iter__cCs|j|j}|r|StdS)z6Return the next 1k chunk from the raw stream. N)rr" StopIteration)r current_chunkrrr__next___s zStreamingBody.__next__ccshd}xL|j|D]>}||jd}x"|ddD]}|jdVq0W|d}qW|rd|jdVdS)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. TNrr))r! splitlines)r chunk_sizependingrlineslinerrr iter_linesis zStreamingBody.iter_linesccs$x|j|}|dkrP|VqWdS)z\Return an iterator to yield chunks of chunk_size bytes from the raw stream. r'N)r)rr+r%rrrr!xs  zStreamingBody.iter_chunkscCs2|jdk r.|jt|jkr.t|jt|jddS)N)Z actual_bytesZexpected_bytes)r rintr)rrrrrs  z$StreamingBody._verify_content_lengthcCs|jjdS)z*Close the underlying http response stream.N)r close)rrrrr1szStreamingBody.close)N)r )__name__ __module__ __qualname____doc__r"rrrr#r&nextr/r!rr1rrrrr s     r cCsx|jd}|j|jd}|ddkr0|j|d<n,|jrRt|j|djd|d<n |j|d<tj |}||j ||j fS)Nprotocol)headers status_coder9i,bodyr8zcontent-length) metadatar8r9contentZhas_streaming_outputr rawgetr create_parserparseZ output_shape)Zoperation_model http_responser7Z response_dictparserrrr get_responses      rC)sysxml.etree.cElementTreexmlloggingZbotocorerZbotocore.hooksrZbotocore.compatrrrZbotocore.exceptionsrrZurllib3.exceptionsrr getLoggerr2robjectr rCrrrrs     s