ó V!¶\c@@s‡ddlmZddlmZddlZddlZddlZddlmZ ddlm Z ddl m Z ddlmZmZmZmZmZmZmZdd lmZmZdd lmZdd lmZmZdd l m!Z!m"Z"ej#e$ƒZ%d e&fd„ƒYZ'de&fd„ƒYZ(de&fd„ƒYZ)de&fd„ƒYZ*d„Z+dej,fd„ƒYZ-dS(i(tabsolute_import(tcontextmanagerN(ttimeout(terrori(tHTTPHeaderDict(tBodyNotHttplibCompatiblet ProtocolErrort DecodeErrortReadTimeoutErrortResponseNotChunkedtIncompleteReadt InvalidHeader(t string_typestPY3(t http_client(t HTTPExceptiont BaseSSLError(t is_fp_closedtis_response_to_headtDeflateDecodercB@s#eZd„Zd„Zd„ZRS(cC@s%t|_d|_tjƒ|_dS(Nt(tTruet _first_tryt_datatzlibt decompressobjt_obj(tself((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt__init__s  cC@st|j|ƒS(N(tgetattrR(Rtname((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt __getattr__scC@sÂ|s |S|js#|jj|ƒS|j|7_y5|jj|ƒ}|rbt|_d|_n|SWnTtjk r½t|_tjtj ƒ|_z|j|jƒSWdd|_XnXdS(N( RRt decompressRtFalsetNoneRRRt MAX_WBITS(Rtdatat decompressed((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR s"    (t__name__t __module__RRR (((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRs  tGzipDecoderStatecB@seZdZdZdZRS(iii(R&R't FIRST_MEMBERt OTHER_MEMBERSt SWALLOW_DATA(((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR(7st GzipDecodercB@s#eZd„Zd„Zd„ZRS(cC@s)tjdtjƒ|_tj|_dS(Ni(RRR#RR(R)t_state(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR@scC@st|j|ƒS(N(RR(RR((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRDscC@sàtƒ}|jtjks"| r,t|ƒSx­trÛy||jj|ƒ7}WnEtj k r–|j}tj|_|tj krt|ƒS‚nX|jj }|s³t|ƒStj |_tj dtj ƒ|_q/WdS(Ni(t bytearrayR-R(R+tbytesRRR RRR*t unused_dataRR#(RR$trettprevious_state((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR Gs"         (R&R'RRR (((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR,>s  t MultiDecodercB@s)eZdZd„Zd„Zd„ZRS(s From RFC7231: If one or more encodings have been applied to a representation, the sender that applied the encodings MUST generate a Content-Encoding header field that lists the content codings in the order in which they were applied. cC@s5g|jdƒD]}t|jƒƒ^q|_dS(Nt,(tsplitt _get_decodertstript _decoders(Rtmodestm((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRfscC@s|jdjƒS(Ni(R8tflush(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR;iscC@s-x&t|jƒD]}|j|ƒ}qW|S(N(treversedR8R (RR$td((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR ls(R&R't__doc__RR;R (((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR3]s  cC@s0d|krt|ƒS|dkr)tƒStƒS(NR4tgzip(R3R,R(tmode((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR6rs    t HTTPResponsecB@sšeZdZddgZdddddgZdd)d d d)d eed)d)d)d)d)ed)d)d „Zd „Z d „Z e d „ƒZ e d„ƒZ d„Zd„Zd„Zd„Zd„Zd„Zed„ƒZd)d)ed„Zd*d)d„Zed„ƒZd„Zd)d„Zd„Zd„Ze d„ƒZd „Zd!„Z d"„Z!d#„Z"d$„Z#d%„Z$d&„Z%d)d)d'„Z&d(„Z'RS(+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, will attempt to decode the body based on the 'content-encoding' header. :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. :param retries: The retries contains the last :class:`~urllib3.util.retry.Retry` that was used during the request. :param enforce_content_length: Enforce content length checking. Body returned by server must match value of Content-Length header, if present. Otherwise, raise error. R?tdeflatei-i.i/i3i4RicC@s˜t|tƒr||_nt|ƒ|_||_||_||_||_||_| |_||_ d|_ d|_ d|_ | |_d|_| |_||_|rÏt|ttfƒrÏ||_ n| |_| |_t|dƒrü||_ nt|_d|_|jjddƒjƒ}d„|jdƒDƒ}d|krZt|_n|j|ƒ|_|r”|j r”|j d|ƒ|_ ndS( Nitreadstransfer-encodingRcs@s|]}|jƒVqdS(N(R7(t.0tenc((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pys ÈsR4tchunkedtdecode_content(!t isinstanceRtheaderststatustversiontreasontstrictRGtretriestenforce_content_lengthR"t_decodert_bodyt_fpt_original_responset_fp_bytes_readtmsgt _request_urlt basestringR/t_poolt _connectionthasattrR!RFt chunk_lefttgettlowerR5Rt _init_lengthtlength_remainingRC(RtbodyRIRJRKRLRMtpreload_contentRGtoriginal_responsetpoolt connectionRURNROtrequest_methodt request_urlttr_enct encodings((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR s@                       cC@s&|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(RJtREDIRECT_STATUSESRIR\R!(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytget_redirect_locationÓscC@s8|j s|j rdS|jj|jƒd|_dS(N(RXRYt _put_connR"(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt release_connàscC@s-|jr|jS|jr)|jdtƒSdS(Nt cache_content(RQRRRCR(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR$çs  cC@s|jS(N(RY(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRdðscC@s t|jƒS(N(RRR(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytisclosedôscC@s|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). (RT(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyttell÷scC@s;|jjdƒ}|d k rÍ|jr8tjdƒd Syctg|jdƒD]}t|ƒ^qNƒ}t |ƒdkrŽt d|ƒ‚n|j ƒ}Wnt k r´d }qÍX|dkrÍd }qÍnyt|j ƒ}Wnt k rùd}nX|d ks.d |kod kns.|d kr7d}n|S(sM Set initial length value for Response content if available. scontent-lengthsÒReceived response with both Content-Length and Transfer-Encoding set. This is expressly forbidden by RFC 7230 sec 3.3.2. Ignoring Content-Length and attempting to process response as Transfer-Encoding: chunked.R4is8Content-Length contained multiple unmatching values (%s)iiÌi0idiÈtHEADN(iÌi0(RIR\R"RFtlogtwarningtsetR5tinttlenR tpopt ValueErrorRJ(RRetlengthtvaltlengthsRJ((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR^ÿs,   .       4 cC@s¼|jjddƒjƒ}|jdkr¸||jkrKt|ƒ|_q¸d|kr¸g|jdƒD]'}|jƒ|jkrg|jƒ^qg}t |ƒrµt|ƒ|_qµq¸ndS(s= Set-up the _decoder attribute if necessary. scontent-encodingRR4N( RIR\R]RPR"tCONTENT_DECODERSR6R5R7Rv(Rtcontent_encodingteRh((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt _init_decoder/s = cC@s˜y(|r'|jr'|jj|ƒ}nWnJttjfk rt}|jjddƒjƒ}td||ƒ‚nX|r”|r”||j ƒ7}n|S(sN Decode the data passed in and potentially flush the decoder. scontent-encodingRsEReceived response with content-encoding: %s, but failed to decode it.( RPR tIOErrorRRRIR\R]Rt_flush_decoder(RR$RGt flush_decoderR~R}((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt_decode>s cC@s0|jr,|jjdƒ}||jjƒSdS(sk Flushes the decoder. Should only be called if the decoder is actually being used. R(RPR R;(Rtbuf((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRPs cc@st}z¦y dVWntk r:t|jddƒ‚nktk ry}dt|ƒkra‚nt|jddƒ‚n,ttfk r¤}t d||ƒ‚nXt }Wd|sê|j rÎ|j j ƒn|j rê|j j ƒqên|j r|j jƒr|jƒnXdS(sç Catch low-level python exceptions, instead re-raising urllib3 variants, so that low-level exceptions are not leaked in the high-level api. On exit, release the connection back to the pool. NsRead timed out.sread operation timed outsConnection broken: %r(R!t SocketTimeoutRRXR"RtstrRt SocketErrorRRRStcloseRYRoRm(Rt clean_exitR~((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt_error_catcher[s(      cC@sY|jƒ|dkr"|j}n|jdkr5dSt}d}|jƒš|dkrr|jjƒ}t}nqt}|jj|ƒ}|dkrã| rã|jjƒt}|j rã|j dkrãt |j |j ƒ‚qãnWdQX|rU|j t |ƒ7_ |j dk r+|j t |ƒ8_ n|j|||ƒ}|rU||_qUn|S(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.) Ni(iN(RR"RGRRR!RŠRCRRˆROR_R RTRvRƒRQ(RtamtRGRnR‚R$((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRC”s4       !iicc@s}|jr=|jƒr=xa|j|d|ƒD] }|Vq+Wn<x9t|jƒsx|jd|d|ƒ}|r@|Vq@q@WdS(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. RGR‹N(RFtsupports_chunked_readst read_chunkedRRRRC(RR‹RGtlineR$((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytstreamÙs cK@sš|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``. RMiR`RIRJRKRLRb( RURHRR titemst from_httplibRRJRKRL(t ResponseClstrt response_kwRIRMtresp((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR‘ós      cC@s|jS(N(RI(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt getheadersscC@s|jj||ƒS(N(RIR\(RRtdefault((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt getheaderscC@s|jS(N(RI(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytinfoscC@s6|js|jjƒn|jr2|jjƒndS(N(tclosedRRRˆRY(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRˆs  cC@sV|jdkrtSt|jdƒr2|jjƒSt|jdƒrN|jjStSdS(NRoRš(RRR"RRZRoRš(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRš#s  cC@sM|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(RRR"R€RZR›(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR›.s  cC@s2|jdk r.t|jdƒr.|jjƒSdS(NR;(RRR"RZR;(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyR;7s!cC@stS(N(R(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytreadable;scC@sI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(RCRv(Rtbttemp((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytreadinto?s cC@st|jdƒS(sú Checks if the underlying file-like object looks like a httplib.HTTPResponse object. We do this by testing for the fp attribute. If it is present we assume it returns raw chunks as processed by read_chunked(). tfp(RZRR(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRŒHscC@s‚|jdk rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn*tk r}|jƒt j |ƒ‚nXdS(Nt;iii( R[R"RRR treadlineR5RuRxRˆthttplibR (RRŽ((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt_update_chunk_lengthQs  cC@sød}|dkrI|jj|jƒ}|}|jjdƒd|_n«||jkrƒ|jj|ƒ}|j||_|}nq||jkrÆ|jj|ƒ}|jjdƒd|_|}n.|jj|jƒ}|jjdƒd|_|S(Ni(R"RRt _safe_readR[(RR‹treturned_chunktchunktvalue((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyt _handle_chunk_s&      c c@sj|jƒ|js"tdƒ‚n|jƒs=tdƒ‚n|jƒ|jrst|jƒrs|jjƒdS|j j dkr‰dSx_t rê|j ƒ|jdkr¯Pn|j|ƒ}|j|d|dtƒ}|rŒ|VqŒqŒW|r|jƒ}|r|Vqnx6t rF|j j jƒ}|s3Pn|dkrPqqW|jr`|jjƒnWdQXdS(sÆ Similar to :meth:`HTTPResponse.read`, but with an additional parameter: ``decode_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. sHResponse is not chunked. Header 'transfer-encoding: chunked' is missing.sgBody should be httplib.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NiRGR‚s (RRFR RŒRRŠRSRRˆRRR R"RR¤R[R©RƒR!RR¢(RR‹RGR§tdecodedRŽ((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRusD                cC@s=|jdk r2t|jjƒr2|jjdjS|jSdS(sÄ Returns the URL that was the source of this response. If the request that generated this response redirected, this method will return the final redirect location. iÿÿÿÿN(RNR"Rvthistorytredirect_locationRV(R((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pytgeturl¸s!Ni((R&R'R>R|RjR"RR!RRkRmtpropertyR$RdRoRpR^RRƒRRRŠRCRt classmethodR‘R–R˜R™RˆRšR›R;RœRŸRŒR¤R©RR­(((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyRA|sH   /     0   9E        C(.t __future__Rt contextlibRRtiotloggingtsocketRR…RR‡t _collectionsRt exceptionsRRRRR R R t packages.sixR RWR tpackages.six.movesRR£RdRRt util.responseRRt getLoggerR&RrtobjectRR(R,R3R6tIOBaseRA(((s3/tmp/pip-install-usGedi/urllib3/urllib3/response.pyts&   4!