ó `8(Zc@@s4ddlmZddlmZddlZddlZddlmZddlm Z ddl m Z ddl mZmZmZmZdd lmZmZmZdd lmZdd lmZmZdd lmZmZd e fd„ƒYZ!de fd„ƒYZ"d„Z#dej$fd„ƒYZ%dS(i(tabsolute_import(tcontextmanagerN(ttimeout(terrori(tHTTPHeaderDict(t ProtocolErrort DecodeErrortReadTimeoutErrortResponseNotChunked(t string_typest binary_typetPY3(t http_client(t HTTPExceptiont BaseSSLError(t is_fp_closedtis_response_to_headtDeflateDecodercB@s#eZd„Zd„Zd„ZRS(cC@s(t|_tƒ|_tjƒ|_dS(N(tTruet _first_tryR t_datatzlibt decompressobjt_obj(tself((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt__init__s  cC@st|j|ƒS(N(tgetattrR(Rtname((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt __getattr__scC@s¡|s |S|js#|jj|ƒS|j|7_y|jj|ƒSWnTtjk rœt|_tjtj ƒ|_z|j|jƒSWdd|_XnXdS(N( RRt decompressRRRtFalseRt MAX_WBITStNone(Rtdata((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRs  (t__name__t __module__RRR(((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRs  t GzipDecodercB@s#eZd„Zd„Zd„ZRS(cC@stjdtjƒ|_dS(Ni(RRRR(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR1scC@st|j|ƒS(N(RR(RR((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR4scC@s|s |S|jj|ƒS(N(RR(RR!((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR7s(R"R#RRR(((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR$/s  cC@s|dkrtƒStƒS(Ntgzip(R$R(tmode((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt _get_decoder=s t HTTPResponsec B@s^eZdZddgZdddddgZdd$d d d$d eed$d$d$d „ Zd „Zd „Z e d „ƒZ e d„ƒZ d„Z d„Zd„Zd„Zed„ƒZd$d$ed„Zd%d$d„Zed„ƒZd„Zd$d„Zd„Ze d„ƒZd„Zd„Zd„Zd „Zd!„Z d"„Z!d$d$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, 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 C@sbt|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|r^|j r^|jd|ƒ|_ ndS( Nitreadstransfer-encodingR*cs@s|]}|jƒVqdS(N(tstrip(t.0tenc((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pys ƒst,tchunkedtdecode_content(t isinstanceRtheaderststatustversiontreasontstrictR1R t_decodert_bodyt_fpt_original_responset_fp_bytes_readt basestringR t_poolt _connectionthasattrRR0t chunk_lefttgettlowertsplitRR+(RtbodyR3R4R5R6R7tpreload_contentR1toriginal_responsetpoolt connectionttr_enct encodings((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRas6                   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(R4tREDIRECT_STATUSESR3RBR(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pytget_redirect_location‹scC@s8|j s|j rdS|jj|jƒd|_dS(N(R>R?t _put_connR (R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt release_conn˜scC@s-|jr|jS|jr)|jdtƒSdS(Nt cache_content(R9R:R+R(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR!Ÿs  cC@s|jS(N(R?(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRI¨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). (R<(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyttell¬scC@sO|jjddƒjƒ}|jdkrK||jkrKt|ƒ|_ndS(s< Set-up the _decoder attribute if necessar. scontent-encodingR*N(R3RBRCR8R tCONTENT_DECODERSR'(Rtcontent_encoding((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt _init_decoder´scC@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-encodingR*sEReceived response with content-encoding: %s, but failed to decode it.( R8RtIOErrorRRR3RBRCRt_flush_decoder(RR!R1t flush_decoderteRT((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/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*(R8Rtflush(Rtbuf((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRWÐs 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(Rt SocketTimeoutRR>R RtstrR t SocketErrorRRR;tcloseR?tisclosedRP(Rt clean_exitRY((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt_error_catcherÛs(      cC@s|jƒ|dkr"|j}n|jdkr5dSt}d}|jƒj|dkrr|jjƒ}t}nAt}|jj|ƒ}|dkr³| r³|jjƒt}nWdQX|rþ|j t |ƒ7_ |j |||ƒ}|rþ||_ qþn|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( RUR R1R:RRcR+RR`R<tlenRZR9(RtamtR1RQRXR!((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR+s,       iicc@sq|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. R1ReN(R0t read_chunkedRR:R+(RReR1tlineR!((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pytstreamPs  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``. R7iRER3R4R5R6RG( tmsgR2RR titemst from_httplibRR4R5R6(t ResponseClstrt response_kwR3R7tresp((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRkjs      cC@s|jS(N(R3(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt getheadersˆscC@s|jj||ƒS(N(R3RB(RRtdefault((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt getheader‹scC@s6|js|jjƒn|jr2|jjƒndS(N(tclosedR:R`R?(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR`s  cC@sV|jdkrtSt|jdƒr/|jjSt|jdƒrN|jjƒStSdS(NRsRa(R:R RR@RsRa(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRs–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(R:R RVR@Rt(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRt¡s  cC@s2|jdk r.t|jdƒr.|jjƒSdS(NR[(R:R R@R[(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR[ªs!cC@stS(N(R(R((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pytreadable®scC@sI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(R+Rd(Rtbttemp((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pytreadinto²s cC@s‚|jdk rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn*tk r}|jƒt j |ƒ‚nXdS(Nt;iii( RAR R:tfptreadlineRDtintt ValueErrorR`thttplibtIncompleteRead(RRg((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt_update_chunk_length»s  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 R:t _safe_readRA(RRetreturned_chunktchunktvalue((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyt _handle_chunkÉs&      c c@s9|jƒ|js"tdƒ‚n|jrKt|jƒrK|jjƒdS|jƒÜx_tr¹|jƒ|j dkr~Pn|j |ƒ}|j |d|dt ƒ}|r[|Vq[q[W|rÝ|j ƒ}|rÝ|VqÝnx6tr|jjjƒ}|sPn|dkràPqàqàW|jr/|jjƒnWdQXdS(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.NiR1RXs (RUR0RR;RR`RcRR€RAR…RZRRWR:RzR{(RReR1RƒtdecodedRg((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyRfßs:              Ni(#R"R#t__doc__RSRMR RRRNRPtpropertyR!RIRRRURZRWRRcRR+Rht classmethodRkRpRrR`RsRtR[RuRxR€R…Rf(((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyR(Ds:  (     9<       (&t __future__Rt contextlibRRtiotsocketRR]RR_t _collectionsRt exceptionsRRRRt packages.sixR R=R R tpackages.six.movesR R~RIR Rt util.responseRRtobjectRR$R'tIOBaseR((((sK/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/packages/urllib3/response.pyts  "