ó 9(Zc@s!yddljZWnek r2ddlZnXddlZddlZddlmZddl m Z ddl m Z m Z mZmZddlmZmZmZddlmZmZddlmZd efd „ƒYZd efd „ƒYZd „Zdejfd„ƒYZdS(iÿÿÿÿN(ttimeouti(tHTTPHeaderDict(t ProtocolErrort DecodeErrortReadTimeoutErrortResponseNotChunked(t string_typest binary_typetPY3(t HTTPExceptiont BaseSSLError(t is_fp_closedtDeflateDecodercBs#eZd„Zd„Zd„ZRS(cCs(t|_tƒ|_tjƒ|_dS(N(tTruet _first_tryRt_datatzlibt decompressobjt_obj(tself((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt__init__s  cCst|j|ƒS(N(tgetattrR(Rtname((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt __getattr__scCs¡|s |S|js#|jj|ƒS|j|7_y|jj|ƒSWnTtjk rœt|_tjtj ƒ|_z|j|jƒSWdd|_XnXdS(N( RRt decompressRRterrortFalseRt MAX_WBITStNone(Rtdata((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRs  (t__name__t __module__RRR(((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR s  t GzipDecodercBs#eZd„Zd„Zd„ZRS(cCstjdtjƒ|_dS(Ni(RRRR(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR1scCst|j|ƒS(N(RR(RR((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR4scCs|s |S|jj|ƒS(N(RR(RR((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR7s(RRRRR(((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR /s  cCs|dkrtƒStƒS(Ntgzip(R R (tmode((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt _get_decoder=s t HTTPResponsec Bs7eZdZddgZdddddgZdd!d d d!d eed!d!d!d „ Zd „Zd „Z e d „ƒZ d„Z d„Z d„Zd!d!ed„Zd"d!d„Zed„ƒZd„Zd!d„Zd„Ze d„ƒZd„Zd„Zd„Zd„Zd„Zd„Zd!d!d „ZRS(#sÅ HTTP Response container. Backwards-compatible to httplib's HTTPResponse but the response ``body`` is loaded and decoded on-demand when the ``data`` property is accessed. This class is also compatible with the Python standard library's :mod:`io` module, and can hence be treated as a readable object in the context of that framework. Extra parameters for behaviour not present in httplib.HTTPResponse: :param preload_content: If True, the response's body will be preloaded during construction. :param decode_content: If True, attempts to decode specific content-encoding's based on headers (like 'gzip' and 'deflate') will be skipped and raw data will be used instead. :param original_response: When this HTTPResponse wrapper is generated from an httplib.HTTPResponse object, it's convenient to include the original for debug purposes. It's otherwise unused. R!tdeflatei-i.i/i3i4tic Cslt|tƒr||_nt|ƒ|_||_||_||_||_||_d|_ d|_ d|_ | |_ d|_ |r«t|ttfƒr«||_ n| |_| |_t|dƒrØ||_ nt|_d|_|jjddƒjƒ} d„| jdƒDƒ} d| kr6t|_n|j rh|rh|j rh|jd|ƒ|_ ndS( Nitreadstransfer-encodingR&css|]}|jƒVqdS(N(tstrip(t.0tenc((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pys ƒst,tchunkedtdecode_content(t isinstanceRtheaderststatustversiontreasontstrictR-Rt_decodert_bodyt_fpt_original_responset_fp_bytes_readt basestringRt_poolt _connectionthasattrRR,t chunk_lefttgettlowertsplitR R'(RtbodyR/R0R1R2R3tpreload_contentR-toriginal_responsetpoolt connectionttr_enct encodings((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRas6                   cCs&|j|jkr"|jjdƒStS(s Should we redirect and where to? :returns: Truthy redirect location string if we got a redirect status code and valid location. ``None`` if redirect status and no location. ``False`` if not a redirect status code. tlocation(R0tREDIRECT_STATUSESR/R>R(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pytget_redirect_location‹scCs8|j s|j rdS|jj|jƒd|_dS(N(R:R;t _put_connR(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt release_conn˜scCs-|jr|jS|jr)|jdtƒSdS(Nt cache_content(R5R6R'R (R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRŸs  cCs|jS(sÛ Obtain the number of bytes pulled over the wire so far. May differ from the amount of content returned by :meth:``HTTPResponse.read`` if bytes are encoded on the wire (e.g, compressed). (R8(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyttell¨scCsO|jjddƒjƒ}|jdkrK||jkrKt|ƒ|_ndS(s< Set-up the _decoder attribute if necessar. scontent-encodingR&N(R/R>R?R4RtCONTENT_DECODERSR#(Rtcontent_encoding((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt _init_decoder°scCs½y(|r'|jr'|jj|ƒ}nWnJttjfk rt}|jjddƒjƒ}td||ƒ‚nX|r¹|r¹|jr¹|jjt ƒƒ}|||jj ƒ7}n|S(sN Decode the data passed in and potentially flush the decoder. scontent-encodingR&sEReceived response with content-encoding: %s, but failed to decode it.( R4RtIOErrorRRR/R>R?RRtflush(RRR-t flush_decoderteRPtbuf((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt_decodeºscCs¢|jƒ|dkr"|j}n|jdkr5dSt}z:yi|dkre|jjƒ}t}nAt}|jj|ƒ}|dkr¦| r¦|jjƒt}nWnŠtk rÏt |j ddƒ‚net k r}dt |ƒkrö‚nt |j ddƒ‚n&t k r3}td||ƒ‚nX|jt|ƒ7_|j|||ƒ}|rp||_n|SWd|jr|jjƒr|jƒnXdS(sP Similar to :meth:`httplib.HTTPResponse.read`, but with two additional parameters: ``decode_content`` and ``cache_content``. :param amt: How much of the content to read. If specified, caching is skipped because it doesn't make sense to cache partial content as the full response. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. :param cache_content: If True, will save the returned data such that the same result is returned despite of the state of the underlying file object. This is useful if you want the ``.data`` property to continue working after having ``.read()`` the file object. (Overridden if ``amt`` is set.) NisRead timed out.sread operation timed outsConnection broken: %r(RQRR-R6RR'R tcloset SocketTimeoutRR:R tstrR RR8tlenRWR5R7tisclosedRL(RtamtR-RMRTRRU((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR'Ís>         iiccsq|jr1xa|j|d|ƒD] }|VqWn<x9t|jƒsl|jd|d|ƒ}|r4|Vq4q4WdS(s_ A generator wrapper for the read() method. A call will block until ``amt`` bytes have been read from the connection or until the connection is closed. :param amt: How much of the content to read. The generator will return up to much data per iteration, but may return less. This is particularly likely when using compressed data. However, the empty string will never be returned. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. R-R]N(R,t read_chunkedR R6R'(RR]R-tlineR((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pytstreams  cKsš|j}t|tƒsEtr3t|jƒƒ}qEtj|ƒ}nt|ddƒ}|d|d|d|jd|jd|j d|d||}|S( s  Given an :class:`httplib.HTTPResponse` instance ``r``, return a corresponding :class:`urllib3.response.HTTPResponse` object. Remaining parameters are passed to the HTTPResponse constructor, along with ``original_response=r``. R3iRAR/R0R1R2RC( tmsgR.RRtitemst from_httplibRR0R1R2(t ResponseClstrt response_kwR/R3tresp((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRc8s      cCs|jS(N(R/(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt getheadersUscCs|jj||ƒS(N(R/R>(RRtdefault((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt getheaderXscCs|js|jjƒndS(N(tclosedR6RX(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRX\s cCsV|jdkrtSt|jdƒr/|jjSt|jdƒrN|jjƒStSdS(NRkR\(R6RR R<RkR\(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRk`s  cCsM|jdkrtdƒ‚n+t|jdƒr=|jjƒStdƒ‚dS(Ns-HTTPResponse has no file to get a fileno fromtfilenosOThe file-like object this HTTPResponse is wrapped around has no file descriptor(R6RRRR<Rl(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRlks  cCs2|jdk r.t|jdƒr.|jjƒSdS(NRS(R6RR<RS(R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyRSts!cCstS(N(R (R((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pytreadablexscCsI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(R'R[(Rtbttemp((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pytreadinto|s cCs‚|jdk rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn*tk r}|jƒt j |ƒ‚nXdS(Nt;iii( R=RR6tfptreadlineR@tintt ValueErrorRXthttplibtIncompleteRead(RR_((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt_update_chunk_length…s  cCsød}|dkrI|jj|jƒ}|}|jjdƒd|_n«||jkrƒ|jj|ƒ}|j||_|}nq||jkrÆ|jj|ƒ}|jjdƒd|_|}n.|jj|jƒ}|jjdƒd|_|S(Ni(RR6t _safe_readR=(RR]treturned_chunktchunktvalue((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyt _handle_chunk“s&      ccs|jƒ|js"tdƒ‚n|jrT|jjjƒdkrT|jjƒdSxPtr¦|jƒ|j dkrzPn|j |ƒ}|j |d|dtƒVqWWx6trß|j j jƒ}|sÌPn|dkrªPqªqªW|jrù|jjƒn|jƒdS(sþ Similar to :meth:`HTTPResponse.read`, but with an additional parameter: ``decode_content``. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. sHResponse is not chunked. Header 'transfer-encoding: chunked' is missing.tHEADNiR-RTs (RQR,RR7t_methodtupperRXR RxR=R}RWR6RrRsRL(RR]R-R{R_((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR^©s,  !       Ni(RRt__doc__RORIRR RRJRLtpropertyRRNRQRWRR'R`t classmethodRcRhRjRXRkRlRSRmRpRxR}R^(((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyR$Ds4  (   Q       ( t http.clienttclientRvt ImportErrorRtiotsocketRRYt _collectionsRt exceptionsRRRRt packages.sixRR9RRRER R t util.responseR tobjectR R R#tIOBaseR$(((sV/tmp/pip-build-wDUJoH/botocore/botocore/vendored/requests/packages/urllib3/response.pyts   "