AlkantarClanX12

Your IP : 3.15.228.171


Current Path : /opt/alt/python37/lib/python3.7/site-packages/urllib3/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/urllib3/__pycache__/response.cpython-37.pyc

B

��`+n�@sXddlmZddlZddlZddlZddlmZddlmZ	ddlm
Zy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/python37/lib/python3.7/site-packages/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�dataZ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+Csr+c@s$eZdZdd�Zdd�Zdd�ZdS)�GzipDecodercCst�dtj�|_tj|_dS)N�)rrr&rr+r-�_state)rrrr r!KszGzipDecoder.__init__cCst|j|�S)N)r"r)rr#rrr r$OszGzipDecoder.__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)Nr1)
�	bytearrayr2r+r/�bytesrr%rrr.�unused_datarr&)rr'�retZprevious_staterrr r%Rs"
zGzipDecoder.decompressN)r(r)r*r!r$r%rrrr r0Jsr0c@seZdZdd�Zdd�ZdS)�
BrotliDecodercCs0t��|_t|jd�r"|jj|_n
|jj|_dS)Nr%)�brotliZDecompressorr�hasattrr%�process)rrrr r!ns
zBrotliDecoder.__init__cCst|jd�r|j��SdS)N�flushr)r9rr;)rrrr r;us
zBrotliDecoder.flushN)r(r)r*r!r;rrrr r7jsr7c@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)rZmodesrrr r!�szMultiDecoder.__init__cCs|jd��S)Nr)rDr;)rrrr r;�szMultiDecoder.flushcCs"xt|j�D]}|�|�}qW|S)N)�reversedrDr%)rr'�drrr r%�szMultiDecoder.decompressN)r(r)r*�__doc__r!r;r%rrrr r<{sr<cCs:d|krt|�S|dkrt�Stdk	r4|dkr4t�St�S)NrB�gzip�br)r<r0r8r7r)�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 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.
    rH�deflateNrIi-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-encodingrMcss|]}|��VqdS)N)r>)r?�encrrr �	<genexpr>�sz(HTTPResponse.__init__.<locals>.<genexpr>rB�chunkedT)�decode_content) �
isinstancer�headers�status�version�reason�strictrR�retries�enforce_content_length�
auto_close�_decoder�_body�_fp�_original_response�_fp_bytes_read�msg�_request_urlr�string_typesr4�_pool�_connectionr9rQ�
chunk_left�get�lowerrC�_init_length�length_remainingrN)r�bodyrTrUrVrWrXZpreload_contentrR�original_response�pool�
connectionrarYrZ�request_methodZrequest_urlr[Ztr_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)rU�REDIRECT_STATUSESrTrg)rrrr �get_redirect_locationsz"HTTPResponse.get_redirect_locationcCs(|jr|jsdS|j�|j�d|_dS)N)rdreZ	_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)rNr�SocketErrorrr	)rrrr �
drain_connszHTTPResponse.drain_conncCs"|jr|jS|jr|jdd�SdS)NT)�
cache_content)r]r^rN)rrrr r'%szHTTPResponse.datacCs|jS)N)re)rrrr rn.szHTTPResponse.connectioncCs
t|j�S)N)rr^)rrrr �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).
        )r`)rrrr �tell5szHTTPResponse.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)r?�valrrr rAWsz-HTTPResponse._init_length.<locals>.<listcomp>rBrz8Content-Length contained multiple unmatching values (%s)r)��i0�d��ZHEAD)
rTrgrQ�log�warning�setrC�lenr�pop�
ValueErrorrzrU)rro�lengthZlengthsrUrrr ri=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-encodingrMNrBcs"g|]}|���jkr|���qSr)r>�CONTENT_DECODERS)r?�e)rrr rA}sz.HTTPResponse._init_decoder.<locals>.<listcomp>)rTrgrhr\r�r=rCr�)r�content_encodingrpr)rr �
_init_decoderqs


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-encodingrMzEReceived response with content-encoding: %s, but failed to decode it.N)r\r%�DECODER_ERROR_CLASSESrTrgrhr�_flush_decoder)rr'rR�
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��Ynvtk
rt}z&dt|�krVt|��t|jdd��Wdd}~XYn4ttfk
r�}ztd||��Wdd}~XYnXd}Wd|s�|j	r�|j	�
�|jr�|j�
�|j	r�|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)�
SocketTimeoutrrdr�strrr	rurr_�closererxrt)rZ
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)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�rRr^r"r�rNr�rZrjr
r`r�r�r])r�amtrRrwr�Z	fp_closedr'rrr rN�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.
        )rR)r�rRN)rQ�supports_chunked_reads�read_chunkedrr^rN)rr�rR�liner'rrr �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``.
        rXr)rkrTrUrVrWrXrl)rarSrr�PY2�from_httplib�itemsr"rUrVrW)ZResponseCls�rZresponse_kwrTrXZresprrr r�Es 	
zHTTPResponse.from_httplibcCs|jS)N)rT)rrrr �
getheadersfszHTTPResponse.getheaderscCs|j�||�S)N)rTrg)rr#�defaultrrr �	getheaderiszHTTPResponse.getheadercCs|jS)N)rT)rrrr �infomszHTTPResponse.infocCs6|js|j��|jr |j��|js2tj�|�dS)N)r�r^r�rer[�io�IOBase)rrrr r�qs

zHTTPResponse.closecCsT|jstjj�|�S|jdkr"dSt|jd�r8|j��St|jd�rL|jjSdSdS)NTrxr�)r[r�r�r��__get__r^r9rx)rrrr 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)r^�IOErrorr9r�)rrrr r��s


zHTTPResponse.filenocCs2|jdk	r.t|jd�r.t|jdd�s.|j��SdS)Nr;r�F)r^r9r"r;)rrrr r;�s
zHTTPResponse.flushcCsdS)NTr)rrrr �readable�szHTTPResponse.readablecCs:|�t|��}t|�dkrdS||dt|��<t|�SdS)Nr)rNr�)r�b�temprrr �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)r9r^)rrrr r��sz#HTTPResponse.supports_chunked_readscCsf|jdk	rdS|jj��}|�dd�d}yt|d�|_Wn&tk
r`|��t||��YnXdS)N�;rrr1)	rfr^r��readlinerCrzr�r�r)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,)r^Z
_safe_readrf)rr�Zreturned_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.zkBody should be http.client.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NrF)rRr�s
)r�rQrr�r
r�r_rr�r^r�r�rfr�r�r�r�)rr�rRr��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���)rYr��historyZredirect_locationrb)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)rR�
rrrr�)r�rC�join�append)r�bufferr��xrrr �__iter__&s
zHTTPResponse.__iter__)rMNrrNrTTNNNNNFNNT)NNF)r�N)N)NN)-r(r)r*rGr�r8rrr!rsrtrv�propertyr'rnrxryrir�r�rrr�r�r�rr�rNr��classmethodr�r�r�r�r�r�r�r;r�r�r�r�r�r�r�r�rrrr rK�sn

1
	4
8
J
!


		
FrK)/�
__future__rr��loggingr�
contextlibr�socketrrurr�r8�ImportError�_collectionsrrnrr	�
exceptionsr
rrr
rrrrrr�packagesrZ
util.responserr�	getLoggerr(r�objectrr+r0r7r<r=r�rKrrrr �<module>s0
0