ó •abc@@saddlmZddlmZddlZddlZddlZddlmZ ddlm Z ddl m Z ddlmZmZmZmZmZmZmZdd lmZmZmZdd lmZdd lmZm Z dd l!m"Z"m#Z#ej$e%ƒZ&d e'fd„ƒYZ(de'fd„ƒYZ)d„Z*dej+fd„ƒYZ,dS(i(tabsolute_import(tcontextmanagerN(ttimeout(terrori(tHTTPHeaderDict(tBodyNotHttplibCompatiblet ProtocolErrort DecodeErrortReadTimeoutErrortResponseNotChunkedtIncompleteReadt InvalidHeader(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((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt__init__s  cC@st|j|ƒS(N(tgetattrR(Rtname((s@/usr/lib/python2.7/site-packages/pip/_vendor/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((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR s"    (t__name__t __module__RRR (((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRs  t GzipDecodercB@s#eZd„Zd„Zd„ZRS(cC@stjdtjƒ|_dS(Ni(RRR#R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR9scC@st|j|ƒS(N(RR(RR((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR<scC@s|s |S|jj|ƒS(N(RR (RR$((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR ?s(R&R'RRR (((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR(7s  cC@s|dkrtƒStƒS(Ntgzip(R(R(tmode((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt _get_decoderEs t HTTPResponsecB@s‚eZdZddgZdddddgZdd'd d d'd eed'd'd'd'ed'd „Zd „Z d „Z e d „ƒZ e d„ƒZ d„Zd„Zd„Zd„Zd„Zed„ƒZd'd'ed„Zd(d'd„Zed„ƒZd„Zd'd„Zd„Zd„Ze d„ƒZd„Zd „Zd!„Z d"„Z!d#„Z"d$„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. :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/i3i4ticC@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|krHt|_n|j|ƒ|_|r‚|j r‚|jd|ƒ|_ ndS( Nitreadstransfer-encodingR.cs@s|]}|jƒVqdS(N(tstrip(t.0tenc((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pys –st,tchunkedtdecode_content(t isinstanceRtheaderststatustversiontreasontstrictR5tretriestenforce_content_lengthR"t_decodert_bodyt_fpt_original_responset_fp_bytes_readt basestringR t_poolt _connectionthasattrR!R4t chunk_lefttgettlowertsplitRt _init_lengthtlength_remainingR/(RtbodyR7R8R9R:R;tpreload_contentR5toriginal_responsetpoolt connectionR<R=trequest_methodttr_enct encodings((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRqs<                     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(R8tREDIRECT_STATUSESR7RHR!(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pytget_redirect_location¡scC@s8|j s|j rdS|jj|jƒd|_dS(N(RDREt _put_connR"(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt release_conn®scC@s-|jr|jS|jr)|jdtƒSdS(Nt cache_content(R?R@R/R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR$µs  cC@s|jS(N(RE(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRQ¾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). (RB(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyttellÂscC@sG|jjdƒ}|d k r8|jr8tjdƒd S|d k rÙyctg|jdƒD]}t|ƒ^qZƒ}t |ƒdkršt d|ƒ‚n|j ƒ}Wnt k rÀd }qÙX|dkrÙd }qÙnyt|j ƒ}Wnt k rd}nX|d ks:d |ko)d kns:|d krCd}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.R3is8Content-Length contained multiple unmatching values (%s)iiÌi0idiÈtHEADN(iÌi0(R7RHR"R4tlogtwarningtsetRJtinttlenR tpopt ValueErrorR8(RRRtlengthtvaltlengthsR8((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRKÊs,  .       4 cC@sO|jjddƒjƒ}|jdkrK||jkrKt|ƒ|_ndS(s= Set-up the _decoder attribute if necessary. scontent-encodingR.N(R7RHRIR>R"tCONTENT_DECODERSR+(Rtcontent_encoding((s@/usr/lib/python2.7/site-packages/pip/_vendor/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.( R>R tIOErrorRRR7RHRIRt_flush_decoder(RR$R5t flush_decoderteRh((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt_decodes cC@s0|jr,|jjdƒ}||jjƒSdS(sk Flushes the decoder. Should only be called if the decoder is actually being used. R.(R>R tflush(Rtbuf((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRks 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 SocketTimeoutRRDR"RtstrRt SocketErrorRRRAtcloseREtisclosedRY(Rt clean_exitRm((s@/usr/lib/python2.7/site-packages/pip/_vendor/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(RiR"R5R@R!RwR/RRtR=RLR RBRaRnR?(RtamtR5RZRlR$((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR/Zs4       !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. R5RxN(R4tsupports_chunked_readst read_chunkedRR@R/(RRxR5tlineR$((s@/usr/lib/python2.7/site-packages/pip/_vendor/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``. R;iRMR7R8R9R:RO( tmsgR6RRtitemst from_httplibRR8R9R:(t ResponseClstrt response_kwR7R;tresp((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR¹s      cC@s|jS(N(R7(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt getheaders×scC@s|jj||ƒS(N(R7RH(RRtdefault((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt getheaderÚscC@s|jS(N(R7(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pytinfoÞscC@s6|js|jjƒn|jr2|jjƒndS(N(tclosedR@RtRE(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRtâs  cC@sV|jdkrtSt|jdƒr2|jjƒSt|jdƒrN|jjStSdS(NRuRˆ(R@R"RRFRuRˆ(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/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(R@R"RjRFR‰(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR‰ôs  cC@s2|jdk r.t|jdƒr.|jjƒSdS(NRo(R@R"RFRo(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRoýs!cC@stS(N(R(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pytreadablescC@sI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(R/Ra(Rtbttemp((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pytreadintos 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(RFR@(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRyscC@s‚|jdk rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn*tk r}|jƒt j |ƒ‚nXdS(Nt;iii( RGR"R@RŽtreadlineRJR`RcRtthttplibR (RR{((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt_update_chunk_lengths  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_readRG(RRxtreturned_chunktchunktvalue((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt _handle_chunk%s&      c c@sT|jƒ|js"tdƒ‚n|jƒs=tdƒ‚n|jrft|jƒrf|jjƒdS|jƒÜx_t rÔ|j ƒ|j dkr™Pn|j |ƒ}|j |d|dtƒ}|rv|VqvqvW|rø|jƒ}|rø|Vqønx6t r0|jjjƒ}|sPn|dkrûPqûqûW|jrJ|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.sgBody should be httplib.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NiR5Rls (RiR4R RyRRARRtRwRR’RGR—RnR!RkR@RŽR(RRxR5R•tdecodedR{((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRz;s@                Ni(&R&R't__doc__RgRVR"RR!RRWRYtpropertyR$RQR[RKRiRnRkRRwR/R|t classmethodRR„R†R‡RtRˆR‰RoRŠRRyR’R—Rz(((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyR,LsB    -    0  9E        (-t __future__Rt contextlibRRtiotloggingtsocketRRqRRst _collectionsRt exceptionsRRRRR R R t packages.sixR RCR Rtpackages.six.movesRR‘RQRRt util.responseRRt getLoggerR&R]tobjectRR(R+tIOBaseR,(((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyts"   4!