usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyc000064400000046204147205636450020610 0ustar00 abc@@saddlmZddlmZddlZddlZddlZddlmZ ddlm Z ddl m Z ddlmZmZmZmZmZmZmZdd lmZmZmZdd lmZdd lmZm Z dd l!m"Z"m#Z#ej$e%Z&d e'fdYZ(de'fdYZ)dZ*dej+fdYZ,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#eZdZdZdZRS(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 rt|_tjtj |_z|j|jSWdd|_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#eZdZdZdZRS(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|dkrtStS(Ntgzip(R(R(tmode((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt _get_decoderEs t HTTPResponsecB@seZdZddgZdddddgZdd'd d d'd eed'd'd'd'ed'd Zd Z d Z e d Z e dZ dZdZdZdZdZedZd'd'edZd(d'dZedZdZd'dZdZdZe dZdZd 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@st|tr||_nt||_||_||_||_||_||_| |_| |_ d|_ d|_ d|_ | |_d|_|rt|ttfr||_ n| |_| |_t|dr||_ nt|_d|_|jjddj}d|jdD}d|krHt|_n|j||_|r|j r|jd||_ ndS( Nitreadstransfer-encodingR.cs@s|]}|jVqdS(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"|jjdStS(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_locationscC@s8|j s|j rdS|jj|jd|_dS(N(RDREt _put_connR"(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt release_connscC@s-|jr|jS|jr)|jdtSdS(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.pyRQscC@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.pyttellscC@sG|jjd}|d k r8|jr8tjdd S|d k ryctg|jdD]}t|^qZ}t |dkrt d|n|j }Wnt k rd }qX|dkrd }qnyt|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-lengthsReceived 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)iii0iditHEADN(ii0(R7RHR"R4tlogtwarningtsetRJtinttlenR tpopt ValueErrorR8(RRRtlengthtvaltlengthsR8((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRKs,  .       4 cC@sO|jjddj}|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_decoderscC@sy(|r'|jr'|jj|}nWnJttjfk rt}|jjddj}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}||jjSdS(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}zy dVWntk r:t|jddnktk ry}dt|krant|jddn,ttfk r}t d||nXt }Wd|s|j r|j j n|j r|j j qn|j r|j jr|jnXdS(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|jjt}|j r|j dkrt |j |j qnWdQX|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=|jr=xa|j|d|D] }|Vq+Wn<x9t|jsx|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.pytstreams cK@s|j}t|tsEtr3t|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.pyRs      cC@s|jS(N(R7(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt getheadersscC@s|jj||S(N(R7RH(RRtdefault((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt getheaderscC@s|jS(N(R7(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pytinfoscC@s6|js|jjn|jr2|jjndS(N(tclosedR@RtRE(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRts  cC@sV|jdkrtSt|jdr2|jjSt|jdrN|jjStSdS(NRuR(R@R"RRFRuR(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRs  cC@sM|jdkrtdn+t|jdr=|jjStddS(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.pyRs  cC@s2|jdk r.t|jdr.|jjSdS(NRo(R@R"RFRo(R((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyRos!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|jdS(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}|jddd}yt|d|_Wn*tk r}|jt j |nXdS(Nt;iii( RGR"R@RtreadlineRJR`RcRtthttplibR (RR{((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyt_update_chunk_lengths  cC@sd}|dkrI|jj|j}|}|jjdd|_n||jkr|jj|}|j||_|}nq||jkr|jj|}|jjdd|_|}n.|jj|j}|jjdd|_|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"tdn|js=tdn|jrft|jrf|jjdS|jx_t r|j |j dkrPn|j |}|j |d|dt}|rv|VqvqvW|r|j}|r|Vqnx6t r0|jjj}|sPn|dkrPqqW|jrJ|jjnWdQXdS(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 RyRRARRtRwRRRGRRnR!RkR@RR(RRxR5RtdecodedR{((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 classmethodRRRRRtRRRoRRRyRRRz(((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.movesRRRQRRt util.responseRRt getLoggerR&R]tobjectRR(R+tIOBaseR,(((s@/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/response.pyts"   4!