Hacked By AnonymousFox

Current Path : /opt/alt/python38/lib/python3.8/site-packages/urllib3/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib/python3.8/site-packages/urllib3/__pycache__/response.cpython-38.pyc

U

��`+n�@sXddlmZddlZddlZddlZddlmZddlmZ	ddlm
ZzddlZWne
k
rldZYnXddlmZddlmZmZdd	lmZmZmZmZmZmZmZmZmZmZdd
lmZddl m!Z!m"Z"e�#e$�Z%Gdd
�d
e&�Z'Gdd�de&�Z(Gdd�de&�Z)edk	�r*Gdd�de&�Z*Gdd�de&�Z+dd�Z,Gdd�dej-�Z.dS)�)�absolute_importN)�contextmanager)�error)�timeout�)�HTTPHeaderDict)�BaseSSLError�
HTTPException)
�BodyNotHttplibCompatible�DecodeError�	HTTPError�IncompleteRead�InvalidChunkLength�
InvalidHeader�
ProtocolError�ReadTimeoutError�ResponseNotChunked�SSLError)�six)�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 �A/opt/alt/python38/lib/python3.8/site-packages/urllib3/response.py�__init__$szDeflateDecoder.__init__cCst|j|�S�N��getattrr�r�namer r r!�__getattr__)szDeflateDecoder.__getattr__cCs�|s|S|js|j�|�S|j|7_z"|j�|�}|rFd|_d|_|WStjk
r�d|_t�tj�|_z|�|j�W�YSd|_XYnXdS)NF)rr�
decompressrrrr�	MAX_WBITS)r�dataZdecompressedr r r!r),s"zDeflateDecoder.decompressN��__name__�
__module__�__qualname__r"r(r)r r r r!r#src@seZdZdZdZdZdS)�GzipDecoderStaterr�N)r-r.r/�FIRST_MEMBER�
OTHER_MEMBERS�SWALLOW_DATAr r r r!r0Csr0c@s$eZdZdd�Zdd�Zdd�ZdS)�GzipDecodercCst�dtj�|_tj|_dS�N�)rrr*rr0r2�_staterr r r!r"KszGzipDecoder.__init__cCst|j|�Sr#r$r&r r r!r(OszGzipDecoder.__getattr__cCs�t�}|jtjks|st|�Sz||j�|�7}Wn<tjk
rn|j}tj|_|tj	krht|�YS�YnX|jj
}|s�t|�Stj	|_t�dtj�|_qdSr6)
�	bytearrayr8r0r4�bytesrr)rrr3�unused_datarr*)rr+�retZprevious_stater r r!r)Rs 
zGzipDecoder.decompressNr,r r r r!r5Jsr5c@seZdZdd�Zdd�ZdS)�
BrotliDecodercCs0t��|_t|jd�r"|jj|_n
|jj|_dS)Nr))�brotliZDecompressorr�hasattrr)�processrr r r!r"ns
zBrotliDecoder.__init__cCst|jd�r|j��SdS)N�flushr)r?rrArr r r!rAus
zBrotliDecoder.flushN)r-r.r/r"rAr r r r!r=jsr=c@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�mr r r!�
<listcomp>�sz)MultiDecoder.__init__.<locals>.<listcomp>�,)�split�	_decoders)rZmodesr r r!r"�szMultiDecoder.__init__cCs|jd��S�Nr)rJrArr r r!rA�szMultiDecoder.flushcCst|j�D]}|�|�}q
|Sr#)�reversedrJr))rr+�dr r r!r)�szMultiDecoder.decompressN)r-r.r/�__doc__r"rAr)r r r r!rB{srBcCs:d|krt|�S|dkrt�Stdk	r4|dkr4t�St�S)NrH�gzip�br)rBr5r>r=r)�moder r r!rC�srCc@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 with :class:`http.client.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 :class:`http.client.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 :class:`http.client.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.
    rO�deflateNrPi-i.i/i3i4�rTFcCst|t�r||_n
t|�|_||_||_||_||_||_|
|_||_	||_
d|_d|_d|_
|	|_d|_||_||_|r�t|tjtf�r�||_|
|_||_t|d�r�||_
d|_d|_|j�dd���}dd�|�d�D�}d	|kr�d
|_|�|�|_|�r|j�s|j|d�|_dS)Nr�readFztransfer-encodingrTcss|]}|��VqdSr#)rD)rE�encr r r!�	<genexpr>�sz(HTTPResponse.__init__.<locals>.<genexpr>rH�chunkedT��decode_content) �
isinstancer�headers�status�version�reason�strictrZ�retries�enforce_content_length�
auto_close�_decoder�_body�_fp�_original_response�_fp_bytes_read�msg�_request_urlr�string_typesr:�_pool�_connectionr?rX�
chunk_left�get�lowerrI�_init_length�length_remainingrU)r�bodyr\r]r^r_r`Zpreload_contentrZ�original_response�pool�
connectionrirarb�request_methodZrequest_urlrcZtr_enc�	encodingsr r r!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)r]�REDIRECT_STATUSESr\rorr r r!�get_redirect_locationsz"HTTPResponse.get_redirect_locationcCs(|jr|jsdS|j�|j�d|_dSr#)rlrmZ	_put_connrr r r!�release_connszHTTPResponse.release_conncCs.z|��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)rUr�SocketErrorrr	rr r r!�
drain_connszHTTPResponse.drain_conncCs"|jr|jS|jr|jdd�SdS)NT)�
cache_content)rerfrUrr r r!r+%szHTTPResponse.datacCs|jSr#)rmrr r r!rv.szHTTPResponse.connectioncCs
t|j�Sr#)rrfrr r r!�isclosed2szHTTPResponse.isclosedcCs|jS)z�
        Obtain the number of bytes pulled over the wire so far. May differ from
        the amount of content returned by :meth:``urllib3.response.HTTPResponse.read``
        if bytes are encoded on the wire (e.g, compressed).
        )rhrr r r!�tell5szHTTPResponse.tellcCs�|j�d�}|dk	r�|jr(t�d�dSz<tdd�|�d�D��}t|�dkrZtd|��|�	�}Wnt
k
r|d}YnX|d	kr�d}zt|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)rE�valr r r!rGWsz-HTTPResponse._init_length.<locals>.<listcomp>rHrz8Content-Length contained multiple unmatching values (%s)r)��i0�d��ZHEAD)
r\rorX�log�warning�setrI�lenr�pop�
ValueErrorr�r])rrw�lengthZlengthsr]r r r!rq=s6���

&zHTTPResponse._init_lengthcsh�j�dd���}�jdkrd|�jkr2t|��_n2d|krd�fdd�|�d�D�}t|�rdt|��_dS)z=
        Set-up the _decoder attribute if necessary.
        �content-encodingrTNrHcs"g|]}|���jkr|���qSr )rD�CONTENT_DECODERS)rE�err r!rG|s�z.HTTPResponse._init_decoder.<locals>.<listcomp>)r\rorprdr�rCrIr�)r�content_encodingrxr rr!�
_init_decoderqs


�zHTTPResponse._init_decoderc
Csx|s|Sz|jr|j�|�}WnD|jk
rb}z$|j�dd���}td||��W5d}~XYnX|rt||��7}|S)zN
        Decode the data passed in and potentially flush the decoder.
        r�rTzEReceived response with content-encoding: %s, but failed to decode it.N)rdr)�DECODER_ERROR_CLASSESr\rorpr�_flush_decoder)rr+rZ�
flush_decoderr�r�r r r!�_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)rdr)rA)r�bufr r r!r��szHTTPResponse._flush_decoderc
cs�d}z�z
dVWn�tk
r2t|jdd��Ynvtk
rt}z&dt	|�krVt
|��t|jdd��W5d}~XYn4ttfk
r�}zt
d||��W5d}~XYnXd}W5|s�|jr�|j��|jr�|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)rg�closermr�r|�
SocketTimeoutrrlr�strrr	r}r)rZ
clean_exitr�r r r!�_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��W5QRX|�r|j
t|�7_
|jdk	r�|jt|�8_|�|||�}|�r||_
|S)aT
        Similar to :meth:`http.client.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�rZrfr%r�rUr�rbrrr
rhr�r�re)r�amtrZrr�Z	fp_closedr+r r r!rU�s:

��

	
zHTTPResponse.read�ccsR|jr*|��r*|j||d�D]
}|Vqn$t|j�sN|j||d�}|r*|Vq*dS)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.
        rY)r�rZN)rX�supports_chunked_reads�read_chunkedrrfrU)rr�rZ�liner+r r r!�stream+s

zHTTPResponse.streamc
Ksb|j}t|t�s.tjr"t�|�}nt|���}t|dd�}|f|||j|j	|j
||d�|��}|S)a
        Given an :class:`http.client.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)rsr\r]r^r_r`rt)rir[rr�PY2�from_httplib�itemsr%r]r^r_)ZResponseCls�rZresponse_kwr\r`Zrespr r r!r�Es$	
��
zHTTPResponse.from_httplibcCs|jSr#�r\rr r r!�
getheadersfszHTTPResponse.getheaderscCs|j�||�Sr#)r\ro)rr'�defaultr r r!�	getheaderiszHTTPResponse.getheadercCs|jSr#r�rr r r!�infomszHTTPResponse.infocCs6|js|j��|jr |j��|js2tj�|�dSr#)r�rfr�rmrc�io�IOBaserr r r!r�qs

zHTTPResponse.closecCsT|jstjj�|�S|jdkr"dSt|jd�r8|j��St|jd�rL|jjSdSdS)NTr�r�)rcr�r�r��__get__rfr?r�rr r r!r�{s

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)rf�IOErrorr?r�rr r r!r��s


�zHTTPResponse.filenocCs2|jdk	r.t|jd�r.t|jdd�s.|j��SdS)NrAr�F)rfr?r%rArr r r!rA�s�
��zHTTPResponse.flushcCsdS)NTr rr r r!�readable�szHTTPResponse.readablecCs:|�t|��}t|�dkrdS||dt|��<t|�SdSrK)rUr�)r�b�tempr r r!�readinto�s
zHTTPResponse.readintocCst|jd�S)a
        Checks if the underlying file-like object looks like a
        :class:`http.client.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?rfrr r r!r��sz#HTTPResponse.supports_chunked_readscCsf|jdk	rdS|jj��}|�dd�d}zt|d�|_Wn&tk
r`|��t||��YnXdS)N�;rrr7)	rnrfr��readlinerIr�r�r�r)rr�r r r!�_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)Nr1)rfZ
_safe_readrn)rr�Zreturned_chunk�chunk�valuer r r!�
_handle_chunk�s&

zHTTPResponse._handle_chunkc	cs�|��|jstd��|��s&td��|����|jrXt|j�rX|j��W5QR�dS|j	j
dkrrW5QR�dS|��|jdkr�q�|�
|�}|j||dd�}|rr|Vqr|r�|��}|r�|V|j	j
��}|s�q�|dkr�q�q�|jr�|j��W5QRXdS)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.zkBody should be http.client.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NrF)rZr�s
)r�rXrr�r
r�rgrr�rfr�r�rnr�r�r�r�)rr�rZr��decodedr�r r r!r��sJ��



�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���)rar��historyZredirect_locationrjrr r r!�geturlszHTTPResponse.geturlccs�g}|jdd�D]n}d|krt|�d�}d�|�|ddV|dd�D]}|dVqJ|drn|dg}q~g}q|�|�q|r�d�|�VdS)NTrY�
rrrr�)r�rI�join�append)r�bufferr��xr r r!�__iter__&s
zHTTPResponse.__iter__)rTNrrNrTTNNNNNFNNT)NNF)r�N)N)NN)-r-r.r/rNr�r>rzr"r{r|r~�propertyr+rvr�r�rqr�r�rrr�r�r�rr�rUr��classmethodr�r�r�r�r�r�r�rAr�r�r�r�r�r�r�r�r r r r!rR�sz 
�
C


4

7
J

 


		
FrR)/�
__future__rr��loggingr�
contextlibr�socketrr}rr�r>�ImportError�_collectionsrrvrr	�
exceptionsr
rrr
rrrrrr�packagesrZ
util.responserr�	getLoggerr-r��objectrr0r5r=rBrCr�rRr r r r!�<module>s0
0
 


Hacked By AnonymousFox1.0, Coded By AnonymousFox