ó &>ôac@sÊddlZddlmZddlmZmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZejeƒZd efd „ƒYZd „ZdS( iÿÿÿÿN(tset_socket_timeout(tIncompleteReadErrortReadTimeoutErrortResponseStreamingError(R(t ProtocolError(tparsers(t ScalarTypes(t XMLParseError(tfirst_non_none_responset StreamingBodycBsweZdZdZd„Zd„Zd d„Zd„Zd„Z e Z de d„Z ed„Z d „Zd „ZRS( seWrapper 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(Ni(t _raw_streamt_content_lengtht _amount_read(tselft raw_streamtcontent_length((s2/usr/lib/fence-agents/bundled/botocore/response.pyt__init__0s  cCsByt|j|ƒWn'tk r=tjddtƒ‚nXdS(s&Set the timeout seconds on the socket.sbCannot access the socket object of a streaming response. It's possible the interface has changed.texc_infoN(RR tAttributeErrortloggerterrortTrue(R ttimeout((s2/usr/lib/fence-agents/bundled/botocore/response.pyR5s   cCsªy|jj|ƒ}WnLtk rC}td|jd|ƒ‚n"tk rd}td|ƒ‚nX|jt|ƒ7_|dks™| r¦|dkr¦|j ƒn|S(shRead at most amt bytes from the stream. If the amt argument is omitted, read all data. t endpoint_urlRiN( R treadtURLLib3ReadTimeoutErrorRturltURLLib3ProtocolErrorRR tlentNonet_verify_content_length(R tamttchunkte((s2/usr/lib/fence-agents/bundled/botocore/response.pyRLs cCs|j|jƒS(sCReturn an iterator to yield 1k chunks from the raw stream. (t iter_chunkst_DEFAULT_CHUNK_SIZE(R ((s2/usr/lib/fence-agents/bundled/botocore/response.pyt__iter__`scCs)|j|jƒ}|r|Stƒ‚dS(s6Return the next 1k chunk from the raw stream. N(RR#t StopIteration(R t current_chunk((s2/usr/lib/fence-agents/bundled/botocore/response.pyt__next__esccsƒd}x[|j|ƒD]J}||jtƒ}x$|d D]}|j|ƒdVq:W|d}qW|r|j|ƒdVndS(sÓReturn 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. tiÿÿÿÿiN(R"t splitlinesR(R t chunk_sizetkeependstpendingR tlinestline((s2/usr/lib/fence-agents/bundled/botocore/response.pyt iter_linesosccs5x.tr0|j|ƒ}|dkr(Pn|VqWdS(s\Return an iterator to yield chunks of chunk_size bytes from the raw stream. R(N(RR(R R*R&((s2/usr/lib/fence-agents/bundled/botocore/response.pyR"~s   cCsO|jdk rK|jt|jƒkrKtd|jdt|jƒƒ‚ndS(Nt actual_bytestexpected_bytes(R RR tintR(R ((s2/usr/lib/fence-agents/bundled/botocore/response.pyRˆs  cCs|jjƒdS(s*Close the underlying http response stream.N(R tclose(R ((s2/usr/lib/fence-agents/bundled/botocore/response.pyR3’sN(t__name__t __module__t__doc__R#RRRRR$R'tnexttFalseR/R"RR3(((s2/usr/lib/fence-agents/bundled/botocore/response.pyR "s       cCs«|jd}i|jd6|jd6}|ddkrG|j|ds u