Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
wiperf / usr / local / lib / python3.7 / dist-packages / urllib3 / __pycache__ / response.cpython-37.pyc
Size: Mime:
B

óFÆltw£5ã@s`ddlmZddlmZddlZddlZddlZddlmZ	ddlm
ZyddlZWne
k
rldZYnXddlmZddlmZmZmZmZmZmZmZmZdd	lmZmZdd
lmZddl m!Z!m"Z"ddl#m$Z$m%Z%e &e'¡Z(Gd
d„de)ƒZ*Gdd„de)ƒZ+Gdd„de)ƒZ,edk	r2Gdd„de)ƒZ-Gdd„de)ƒZ.dd„Z/Gdd„dej0ƒZ1dS)é)Úabsolute_import)ÚcontextmanagerN)Útimeout)Úerroré)ÚHTTPHeaderDict)ÚBodyNotHttplibCompatibleÚ
ProtocolErrorÚDecodeErrorÚReadTimeoutErrorÚResponseNotChunkedÚIncompleteReadÚ
InvalidHeaderÚ	HTTPError)Ústring_typesÚPY3)Úhttp_client)Ú
HTTPExceptionÚBaseSSLError)Úis_fp_closedÚis_response_to_headc@s$eZdZdd„Zdd„Zdd„ZdS)ÚDeflateDecodercCsd|_d|_t ¡|_dS)NTó)Ú
_first_tryÚ_dataÚzlibÚ
decompressobjÚ_obj)Úself©rú5/tmp/pip-install-z4i6eiy2/urllib3/urllib3/response.pyÚ__init__"szDeflateDecoder.__init__cCst|j|ƒS)N)Úgetattrr)rÚnamerrr Ú__getattr__'szDeflateDecoder.__getattr__cCs|s|S|js|j |¡S|j|7_y |j |¡}|rFd|_d|_|Stjk
rŠd|_t tj¡|_z| |j¡Sd|_XYnXdS)NF)rrÚ
decompressrrrrÚ	MAX_WBITS)rÚdataÚdecompressedrrr r%*s"zDeflateDecoder.decompressN)Ú__name__Ú
__module__Ú__qualname__r!r$r%rrrr r!src@seZdZdZdZdZdS)ÚGzipDecoderStaterréN)r)r*r+ÚFIRST_MEMBERÚ
OTHER_MEMBERSÚSWALLOW_DATArrrr r,Asr,c@s$eZdZdd„Zdd„Zdd„ZdS)ÚGzipDecodercCst dtj¡|_tj|_dS)Né)rrr&rr,r.Ú_state)rrrr r!IszGzipDecoder.__init__cCst|j|ƒS)N)r"r)rr#rrr r$MszGzipDecoder.__getattr__cCs¤tƒ}|jtjks|st|ƒSx€y||j |¡7}Wn8tjk
rl|j}tj|_|tj	krft|ƒS‚YnX|jj
}|s‚t|ƒStj	|_t dtj¡|_q WdS)Nr2)
Ú	bytearrayr3r,r0Úbytesrr%rrr/Úunused_datarr&)rr'ÚretÚprevious_staterrr r%Ps"
zGzipDecoder.decompressN)r)r*r+r!r$r%rrrr r1Hsr1c@seZdZdd„Zdd„ZdS)Ú
BrotliDecodercCs0t ¡|_t|jdƒr"|jj|_n
|jj|_dS)Nr%)ÚbrotliZDecompressorrÚhasattrr%Úprocess)rrrr r!ls
zBrotliDecoder.__init__cCst|jdƒr|j ¡SdS)NÚflushr)r;rr=)rrrr r=ss
zBrotliDecoder.flushN)r)r*r+r!r=rrrr r9hsr9c@s(eZdZdZdd„Zdd„Zdd„ZdS)	ÚMultiDecodera
    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.
    cCsdd„| d¡Dƒ|_dS)NcSsg|]}t| ¡ƒ‘qSr)Ú_get_decoderÚstrip)Ú.0Úmrrr ú
<listcomp>ƒsz)MultiDecoder.__init__.<locals>.<listcomp>ú,)ÚsplitÚ	_decoders)rÚmodesrrr r!‚szMultiDecoder.__init__cCs|jd ¡S)Nr)rFr=)rrrr r=…szMultiDecoder.flushcCs"xt|jƒD]}| |¡}qW|S)N)ÚreversedrFr%)rr'Údrrr r%ˆszMultiDecoder.decompressN)r)r*r+Ú__doc__r!r=r%rrrr r>ysr>cCs:d|krt|ƒS|dkrtƒStdk	r4|dkr4tƒStƒS)NrDÚgzipÚbr)r>r1r:r9r)Úmoderrr r?Žsr?c@sleZdZdZddgZedk	r&edg7Zdddd	d
gZdNdd„Zdd„Zdd„Z	dd„Z
edd„ƒZedd„ƒZ
dd„Zdd„Zdd „Zd!d"„ZeejfZedk	r¬eejf7Zd#d$„Zd%d&„Zed'd(„ƒZdOd)d*„ZdPd,d-„Zed.d/„ƒZd0d1„ZdQd2d3„Zd4d5„Z d6d7„Z!ed8d9„ƒZ"d:d;„Z#d<d=„Z$d>d?„Z%d@dA„Z&dBdC„Z'dDdE„Z(dFdG„Z)dRdHdI„Z*dJdK„Z+dLdM„Z,dS)SÚHTTPResponseaº
    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.
    rKÚdeflateNrLi-i.i/i3i4ÚrTFcCst|tƒr||_n
t|ƒ|_||_||_||_||_||_|
|_||_	||_
d|_d|_d|_
|	|_d|_||_||_|rŽt|ttfƒrŽ||_|
|_||_t|dƒrª||_
d|_d|_|j dd¡ ¡}dd„| d¡Dƒ}d	|krêd
|_| |¡|_|r|js|j|d|_dS)NrÚreadFztransfer-encodingrPcss|]}| ¡VqdS)N)r@)rAÚencrrr ú	<genexpr>ùsz(HTTPResponse.__init__.<locals>.<genexpr>rDÚchunkedT)Údecode_content)Ú
isinstancerÚheadersÚstatusÚversionÚreasonÚstrictrUÚretriesÚenforce_content_lengthÚ
auto_closeÚ_decoderÚ_bodyÚ_fpÚ_original_responseÚ_fp_bytes_readÚmsgÚ_request_urlÚ
basestringr5Ú_poolÚ_connectionr;rTÚ
chunk_leftÚgetÚlowerrEÚ_init_lengthÚlength_remainingrQ)rÚbodyrWrXrYrZr[Úpreload_contentrUÚoriginal_responseÚpoolÚ
connectionrdr\r]Úrequest_methodÚrequest_urlr^Útr_encÚ	encodingsrrr r!ÁsB


zHTTPResponse.__init__cCs|j|jkr|j d¡SdS)a
        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.
        ÚlocationF)rXÚREDIRECT_STATUSESrWrj)rrrr Úget_redirect_locationsz"HTTPResponse.get_redirect_locationcCs(|jr|jsdS|j |j¡d|_dS)N)rgrhÚ	_put_conn)rrrr Úrelease_connszHTTPResponse.release_conncCs.y| ¡Wnttttfk
r(YnXdS)zÏ
        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)rQrÚSocketErrorrr)rrrr Ú
drain_connszHTTPResponse.drain_conncCs"|jr|jS|jr|jddSdS)NT)Ú
cache_content)r`rarQ)rrrr r'#szHTTPResponse.datacCs|jS)N)rh)rrrr rr,szHTTPResponse.connectioncCs
t|jƒS)N)rra)rrrr Úisclosed0szHTTPResponse.isclosedcCs|jS)zÛ
        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).
        )rc)rrrr Útell3szHTTPResponse.tellcCsà|j d¡}|dk	rŠ|jr(t d¡dSy<tdd„| d¡Dƒƒ}t|ƒdkrZtd|ƒ‚| 	¡}Wnt
k
r|d}YnX|d	krŠd}yt|jƒ}Wnt
k
r°d	}YnX|d
ksØd|krÎdksØn|d
krÜd	}|S)zM
        Set initial length value for Response content if available.
        zcontent-lengthNzÒ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.cSsg|]}t|ƒ‘qSr)Úint)rAÚvalrrr rCUsz-HTTPResponse._init_length.<locals>.<listcomp>rDrz8Content-Length contained multiple unmatching values (%s)r)éÌi0édéÈÚHEAD)
rWrjrTÚlogÚwarningÚsetrEÚlenrÚpopÚ
ValueErrorrrX)rrsÚlengthÚlengthsrXrrr rl;s0

&zHTTPResponse._init_lengthcshˆj dd¡ ¡}ˆjdkrd|ˆjkr2t|ƒˆ_n2d|krd‡fdd„| d¡Dƒ}t|ƒrdt|ƒˆ_dS)z=
        Set-up the _decoder attribute if necessary.
        zcontent-encodingrPNrDcs"g|]}| ¡ˆjkr| ¡‘qSr)r@ÚCONTENT_DECODERS)rAÚe)rrr rC{sz.HTTPResponse._init_decoder.<locals>.<listcomp>)rWrjrkr_rr?rErŠ)rÚcontent_encodingrvr)rr Ú
_init_decoderos


zHTTPResponse._init_decoderc
Csx|s|Sy|jr|j |¡}WnD|jk
rb}z$|j dd¡ ¡}td||ƒ‚Wdd}~XYnX|rt|| ¡7}|S)zN
        Decode the data passed in and potentially flush the decoder.
        zcontent-encodingrPzEReceived response with content-encoding: %s, but failed to decode it.N)r_r%ÚDECODER_ERROR_CLASSESrWrjrkr
Ú_flush_decoder)rr'rUÚ
flush_decoderrr‘rrr Ú_decode†szHTTPResponse._decodecCs$|jr |j d¡}||j ¡SdS)zk
        Flushes the decoder. Should only be called if the decoder is actually
        being used.
        r)r_r%r=)rÚbufrrr r”œszHTTPResponse._flush_decoderc
csìd}z¤y
dVWntk
r2t|jddƒ‚Ynptk
rn}z dt|ƒkrP‚t|jddƒ‚Wdd}~XYn4ttfk
r }ztd||ƒ‚Wdd}~XYnXd}Wd|sÎ|jr¾|j 	¡|j
rÎ|j
 	¡|jræ|j ¡ræ| ¡XdS)zç
        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.
        FNzRead timed out.zread operation timed outzConnection broken: %rT)
Ú
SocketTimeoutrrgrÚstrrr|r	rbÚcloserhrr{)rÚ
clean_exitrrrr Ú_error_catcher§s(	
 

zHTTPResponse._error_catcherc	Cs| ¡|dkr|j}|jdkr$dSd}t|jddƒ}| ¡v|dkr`|sV|j ¡nd}d}nPd}|st|j |¡nd}|dkr°|s°|j ¡d}|jr°|jdkr°t	|j
|jƒ‚WdQRX|r|j
t|ƒ7_
|jdk	rî|jt|ƒ8_| |||¡}|r||_
|S)aP
        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.)
        NFÚclosedrTr)rN)r’rUrar"rœrQršr]rmr
rcrŠr–r`)rÚamtrUr~r•Z	fp_closedr'rrr rQàs6

	


zHTTPResponse.readéccsZ|jr.| ¡r.xF|j||dD]
}|VqWn(x&t|jƒsT|j||d}|r0|Vq0WdS)a_
        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.
        )rU)ržrUN)rTÚsupports_chunked_readsÚread_chunkedrrarQ)rržrUÚliner'rrr Ústream*szHTTPResponse.streamc
Ks`|j}t|tƒs,tr"t| ¡ƒ}n
t |¡}t|ddƒ}|f|||j|j|j	||dœ|—Ž}|S)a
        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[r)rnrWrXrYrZr[rp)
rdrVrrÚitemsÚfrom_httplibr"rXrYrZ)ÚResponseClsÚrÚresponse_kwrWr[Úresprrr r¥Ds 	

zHTTPResponse.from_httplibcCs|jS)N)rW)rrrr Ú
getheaderseszHTTPResponse.getheaderscCs|j ||¡S)N)rWrj)rr#Údefaultrrr Ú	getheaderhszHTTPResponse.getheadercCs|jS)N)rW)rrrr ÚinfolszHTTPResponse.infocCs6|js|j ¡|jr |j ¡|js2tj |¡dS)N)rraršrhr^ÚioÚIOBase)rrrr ršps

zHTTPResponse.closecCsT|jstjj |¡S|jdkr"dSt|jdƒr8|j ¡St|jdƒrL|jjSdSdS)NTrr)r^r®r¯rÚ__get__rar;r)rrrr rzs

zHTTPResponse.closedcCs6|jdkrtdƒ‚nt|jdƒr*|j ¡Stdƒ‚dS)Nz-HTTPResponse has no file to get a fileno fromÚfilenozOThe file-like object this HTTPResponse is wrapped around has no file descriptor)raÚIOErrorr;r±)rrrr r±‡s


zHTTPResponse.filenocCs2|jdk	r.t|jdƒr.t|jddƒs.|j ¡SdS)Nr=rF)rar;r"r=)rrrr r=’s
zHTTPResponse.flushcCsdS)NTr)rrrr ÚreadablešszHTTPResponse.readablecCs:| t|ƒ¡}t|ƒdkrdS||dt|ƒ…<t|ƒSdS)Nr)rQrŠ)rÚbÚtemprrr Úreadintožs
zHTTPResponse.readintocCst|jdƒS)zú
        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().
        Úfp)r;ra)rrrr r §sz#HTTPResponse.supports_chunked_readscCsf|jdk	rdS|jj ¡}| dd¡d}yt|dƒ|_Wn&tk
r`| ¡t 	|¡‚YnXdS)Nó;rrr2)
rirar·ÚreadlinerErrŒršÚhttplibr
)rr¢rrr Ú_update_chunk_length°s
z!HTTPResponse._update_chunk_lengthcCs¬d}|dkr2|j |j¡}|}|j d¡d|_nv||jkrZ|j |¡}|j||_|}nN||jkrˆ|j |¡}|j d¡d|_|}n |j |j¡}|j d¡d|_|S)Nr-)raÚ
_safe_readri)rržÚreturned_chunkÚchunkÚvaluerrr Ú
_handle_chunk¾s&

zHTTPResponse._handle_chunkc	csò| ¡|jstdƒ‚| ¡s&tdƒ‚| ¡º|jrNt|jƒrN|j ¡dS|j	j
dkr^dSx<| ¡|jdkrtP| 
|¡}|j||dd}|r`|Vq`W|r²| ¡}|r²|Vx |j	j
 ¡}|sÆP|dkr´Pq´W|jrä|j ¡WdQRXdS)aÆ
        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.
        zHResponse is not chunked. Header 'transfer-encoding: chunked' is missing.zgBody should be httplib.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NrF)rUr•s
)r’rTrr rrœrbrršrar·r»rirÀr–r”r¹)rržrUr¾Údecodedr¢rrr r¡ÔsD




zHTTPResponse.read_chunkedcCs.|jdk	r$t|jjƒr$|jjdjS|jSdS)zÄ
        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.
        Néÿÿÿÿ)r\rŠÚhistoryÚredirect_locationre)rrrr ÚgeturlszHTTPResponse.geturlccsœg}x‚|jddD]r}d|krz| d¡}d |¡|ddVx|dd…D]}|dVqNW|drt|dg}q„g}q| |¡qW|r˜d |¡VdS)NT)rUó
rrrrÂ)r£rEÚjoinÚappend)rÚbufferr¾Úxrrr Ú__iter__%s
zHTTPResponse.__iter__)rPNrrNrTTNNNNNFNNT)NNF)rŸN)N)NN)-r)r*r+rJrr:rxr!ryr{r}Úpropertyr'rrrr€rlr’r²rrr“r–r”rrœrQr£Úclassmethodr¥rªr¬r­ršrr±r=r³r¶r r»rÀr¡rÅrËrrrr rN›sn

1
	4
9
J
!


		
FrN)2Ú
__future__rÚ
contextlibrrr®ÚloggingÚsocketrr˜rr|r:ÚImportErrorÚ_collectionsrÚ
exceptionsrr	r
rrr
rrZpackages.sixrrfrZpackages.six.movesrrºrrrrZ
util.responserrÚ	getLoggerr)r‡Úobjectrr,r1r9r>r?r¯rNrrrr Ú<module>s2
(