Viewing File: /opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyo

ó
“tÆ_c@@sÜddlmZddlmZddlZddlZddlZddlmZ	ddlm
ZyddlZWne
k
rdZnXddlmZddlmZmZmZmZmZmZmZmZdd	lmZmZdd
lmZ ddl!m"Z"m#Z#ddl$m%Z%m&Z&ej'e(ƒZ)d
e*fd„ƒYZ+de*fd„ƒYZ,de*fd„ƒYZ-edk	r de*fd„ƒYZ.nde*fd„ƒYZ/d„Z0dej1fd„ƒYZ2dS(i(tabsolute_import(tcontextmanagerN(ttimeout(terrori(tHTTPHeaderDict(tBodyNotHttplibCompatiblet
ProtocolErrortDecodeErrortReadTimeoutErrortResponseNotChunkedtIncompleteReadt
InvalidHeadert	HTTPError(tstring_typestPY3(thttp_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((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt__init__"s		cC@st|j|ƒS(N(tgetattrR(Rtname((sM/opt/alt/python35/lib/python3.5/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((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR!*s"			(t__name__t
__module__RR R!(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR!s		tGzipDecoderStatecB@seZdZdZdZRS(iii(R'R(tFIRST_MEMBERt
OTHER_MEMBERStSWALLOW_DATA(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR)AstGzipDecodercB@s#eZd„Zd„Zd„ZRS(cC@s)tjdtjƒ|_tj|_dS(Ni(RRR$RR)R*t_state(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRIscC@st|j|ƒS(N(RR(RR((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR MscC@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+tunused_dataRR$(RR%trettprevious_state((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR!Ps"	
		

(R'R(RR R!(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR-Hs		t
BrotliDecodercB@s#eZd„Zd„Zd„ZRS(cC@stjƒ|_dS(N(tbrotlitDecompressorR(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRlscC@s2t|jdƒr"|jj|ƒS|jj|ƒS(NR!(thasattrRR!tprocess(RR%((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR!oscC@s#t|jdƒr|jjƒSdS(NtflushR(R7RR9(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR9ts
(R'R(RR!R9(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR4hs		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((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRƒscC@s|jdjƒS(Ni(R?R9(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR9†scC@s-x&t|jƒD]}|j|ƒ}qW|S(N(treversedR?R!(RR%td((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR!‰s(R'R(t__doc__RR9R!(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR:zs		cC@sOd|krt|ƒS|dkr)tƒStdk	rH|dkrHtƒStƒS(NR;tgziptbr(R:R-R5R#R4R(tmode((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR=s
tHTTPResponsecB@sùeZdZddgZed,k	r4edg7ZndddddgZd	d,d
d
d,d
eed,d,d,d,d,ed,d,ed„Z	d„Z
d
„Zd„Ze
d„ƒZe
d„ƒZd„Zd„Zd„Zd„ZeejfZed,k	reejf7Znd„Zd„Zed„ƒZd,d,ed„Zd-d,d„Zed„ƒZd„Z d,d„Z!d„Z"d „Z#e
d!„ƒZ$d"„Z%d#„Z&d$„Z'd%„Z(d&„Z)d'„Z*d(„Z+d,d,d)„Z,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.
    REtdeflateRFi-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|krct|_n|j|ƒ|_ |r|j
r|j!d|ƒ|_
ndS(	Nitreadstransfer-encodingRcs@s|]}|jƒVqdS(N(R>(t.0tenc((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pys	<genexpr>úsR;tchunkedtdecode_content("t
isinstanceRtheaderststatustversiontreasontstrictRNtretriestenforce_content_lengtht
auto_closeR#t_decodert_bodyt_fpt_original_responset_fp_bytes_readtmsgt_request_urlt
basestringR0t_poolt_connectionR7R"RMt
chunk_lefttgettlowerR<Rt_init_lengthtlength_remainingRJ(RtbodyRPRQRRRSRTtpreload_contentRNtoriginal_responsetpoolt
connectionR]RURVtrequest_methodtrequest_urlRWttr_enct	encodings((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRÂsB																			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(RQtREDIRECT_STATUSESRPRcR"(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pytget_redirect_locationscC@s8|js|jrdS|jj|jƒd|_dS(N(R`Rat	_put_connR#(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pytrelease_connscC@s2y|jƒWnttttfk
r-nXdS(sÏ
        Read and discard any remaining HTTP response data in the response connection.

        Unread data in the HTTPResponse connection blocks the connection from being released back to the pool.
        N(RJRtSocketErrorRR(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt
drain_connscC@s-|jr|jS|jr)|jdtƒSdS(Nt
cache_content(RYRZRJR(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR%$s		cC@s|jS(N(Ra(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRk-scC@s
t|jƒS(N(RRZ(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pytisclosed1scC@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((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyttell4scC@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.|dkr7d}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.R;is8Content-Length contained multiple unmatching values (%s)iiÌi0idiÈtHEADN(iÌi0(RPRcR#RMtlogtwarningtsetR<tinttlenRtpopt
ValueErrorRQ(RRltlengthtvaltlengthsRQ((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRe<s0	.




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-encodingRR;N(
RPRcRdRXR#tCONTENT_DECODERSR=R<R>R(Rtcontent_encodingteRo((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt
_init_decoderps'cC@s|s
|Sy"|jr+|jj|ƒ}nWnD|jk
rr}|jjddƒjƒ}td||ƒ‚nX|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.(RXR!tDECODER_ERROR_CLASSESRPRcRdRt_flush_decoder(RR%RNt
flush_decoderR‡R†((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/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(RXR!R9(Rtbuf((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRŠs	cc@st}z¦y	dVWntk
r:t|jddƒ‚nktk
ry}dt|ƒkra‚nt|jddƒ‚n,ttfk
r¤}t	d||ƒ‚nXt
}Wd|sê|jrÎ|jjƒn|j
rê|j
jƒqên|jr|jjƒ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
SocketTimeoutRR`R#RtstrRRuRRR[tcloseRaRxRt(Rt
clean_exitR‡((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt_error_catcher¨s(		

		c	C@s€|jƒ|dkr"|j}n|jdkr5dSt}t|jdtƒ}|jƒ²|dkr|s~|jjƒnd}t}n}t}|s«|jj|ƒnd}|dkr
|r
|jj	ƒt}|j
r
|jdkr
t|j
|jƒ‚q
nWdQX|r||j
t|ƒ7_
|jdk	rR|jt|ƒ8_n|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.)
        NtclosedRi(iN(RˆR#RNRZR"RR’RJRRRVRfR
R\RRŒRY(RtamtRNRwR‹t	fp_closedR%((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRJás8

		
	!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.
        RNR”N(RMtsupports_chunked_readstread_chunkedRRZRJ(RR”RNtlineR%((sM/opt/alt/python35/lib/python3.5/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``.
        RTiRgRPRQRRRSRi(
R]RORRtitemstfrom_httplibRRQRRRS(tResponseClstrtresponse_kwRPRTtresp((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR›Es 						cC@s|jS(N(RP(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt
getheadersfscC@s|jj||ƒS(N(RPRc(RRtdefault((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt	getheaderiscC@s|jS(N(RP(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pytinfomscC@sR|js|jjƒn|jr2|jjƒn|jsNtjj|ƒndS(N(R“RZRRaRWtiotIOBase(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRqs			cC@sr|jstjjj|ƒS|jdkr/tSt|jdƒrN|jj	ƒSt|jdƒrj|jjStSdS(NRxR“(
RWR¤R¥R“t__get__RZR#RR7Rx(R((sM/opt/alt/python35/lib/python3.5/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(RZR#tIOErrorR7R§(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR§ˆs
cC@sH|jdk	rDt|jdƒrDt|jdtƒrD|jjƒSdS(NR9R“(RZR#R7RR"R9(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR9“scC@stS(N(R(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pytreadable›scC@sI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(RJR(Rtbttemp((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/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(R7RZ(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR–¨scC@s‚|jdk	rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn*tk
r}|jƒt	j
|ƒ‚nXdS(Nt;iii(RbR#RZR­treadlineR<R~RRthttplibR
(RR˜((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/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#RZt
_safe_readRb(RR”treturned_chunktchunktvalue((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt
_handle_chunk¿s&				cc@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.NiRNR‹s
(RˆRMR	R–RR’R[RRRZR­R#RR±RbR¶RŒR"RŠR¯(RR”RNR´tdecodedR˜((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyR—ÕsD
	

	
		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(RUR#Rthistorytredirect_locationR^(R((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pytgeturls!cc@sÄg}x |jdtƒD]Œ}d|kr˜|jdƒ}dj|ƒ|ddVx|dd!D]}|dVqbW|dr|dg}q¥g}q|j|ƒqW|rÀdj|ƒVndS(NRNs
Riiiÿÿÿÿ(R™RR<tjointappend(RtbufferR´tx((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt__iter__&s

	Ni(/R'R(RDR…R5R#RqRR"RRrRtRvtpropertyR%RkRxRyReRˆR¨RRR‰RŒRŠRR’RJR™tclassmethodR›R R¢R£RR“R§R9R©R¬R–R±R¶R—RºR¿(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyRHœsn1	
						4			9J!			

									F	(3t
__future__Rt
contextlibRRR¤tloggingtsocketRRŽRRuR5tImportErrorR#t_collectionsRt
exceptionsRRRRR	R
RRtpackages.sixR
R_Rtpackages.six.movesRR°RkRRt
util.responseRRt	getLoggerR'R{tobjectRR)R-R4R:R=R¥RH(((sM/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/urllib3/response.pyt<module>s2

:
 	
Back to Directory File Manager