AlkantarClanX12

Your IP : 3.138.69.101


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

B

͈�``S�@s�dZddlZddlZddlmZmZddlmZddl	m
Z
ddl	mZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1m2Z2mZmZm3Z3m4Z4m5Z5m6Z6ddl7m8Z8yddl9m:Z:Wne;k
�r�dd�Z:YnXdZ<dZ=dZ>dZ?Gd d!�d!e@�ZAGd"d#�d#eA�ZBdS)$z�
requests.adapters
~~~~~~~~~~~~~~~~~

This module contains the transport adapters that Requests uses to define
and maintain connections.
�N)�PoolManager�proxy_from_url)�HTTPResponse)�	parse_url)�Timeout)�Retry)�ClosedPoolError)�ConnectTimeoutError)�	HTTPError)�
MaxRetryError)�NewConnectionError)�
ProxyError)�
ProtocolError)�ReadTimeoutError)�SSLError)�
ResponseError)�LocationValueError�)�Response)�urlparse�
basestring)�DEFAULT_CA_BUNDLE_PATH�extract_zipped_paths�get_encoding_from_headers�prepend_scheme_if_needed�get_auth_from_url�
urldefragauth�select_proxy)�CaseInsensitiveDict)�extract_cookies_to_jar)	�ConnectionError�ConnectTimeout�ReadTimeoutrr
�
RetryError�
InvalidSchema�InvalidProxyURL�
InvalidURL)�_basic_auth_str)�SOCKSProxyManagercOstd��dS)Nz'Missing dependencies for SOCKS support.)r$)�args�kwargs�r+�B/opt/alt/python37/lib/python3.7/site-packages/requests/adapters.pyr(.sr(F�
cs2eZdZdZ�fdd�Zddd�Zd	d
�Z�ZS)�BaseAdapterzThe Base Transport Adaptercstt|���dS)N)�superr.�__init__)�self)�	__class__r+r,r0:szBaseAdapter.__init__FNTcCst�dS)aCSends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        N)�NotImplementedError)r1�request�stream�timeout�verify�cert�proxiesr+r+r,�send=szBaseAdapter.sendcCst�dS)z!Cleans up adapter specific items.N)r3)r1r+r+r,�closeOszBaseAdapter.close)FNTNN)�__name__�
__module__�__qualname__�__doc__r0r:r;�
__classcell__r+r+)r2r,r.7s

r.cs�eZdZdZdddddgZeeeef�fdd�	Zd	d
�Z	dd�Z
efd
d�Zdd�Zdd�Z
dd�Zd$dd�Zdd�Zdd�Zdd�Zdd�Zd%d"d#�Z�ZS)&�HTTPAdaptera�The built-in HTTP Adapter for urllib3.

    Provides a general-case interface for Requests sessions to contact HTTP and
    HTTPS urls by implementing the Transport Adapter interface. This class will
    usually be created by the :class:`Session <Session>` class under the
    covers.

    :param pool_connections: The number of urllib3 connection pools to cache.
    :param pool_maxsize: The maximum number of connections to save in the pool.
    :param max_retries: The maximum number of retries each connection
        should attempt. Note, this applies only to failed DNS lookups, socket
        connections and connection timeouts, never to requests where data has
        made it to the server. By default, Requests does not retry failed
        connections. If you need granular control over the conditions under
        which we retry a request, import urllib3's ``Retry`` class and pass
        that instead.
    :param pool_block: Whether the connection pool should block for connections.

    Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> a = requests.adapters.HTTPAdapter(max_retries=3)
      >>> s.mount('http://', a)
    �max_retries�config�_pool_connections�
_pool_maxsize�_pool_blockcsd|tkrtddd�|_nt�|�|_i|_i|_tt|���||_	||_
||_|j|||d�dS)NrF)�read)�block)
�DEFAULT_RETRIESrrBZfrom_intrC�
proxy_managerr/rAr0rDrErF�init_poolmanager)r1Zpool_connectionsZpool_maxsizerBZ
pool_block)r2r+r,r0qszHTTPAdapter.__init__cs�fdd��jD�S)Ncsi|]}t�|d�|�qS)N)�getattr)�.0�attr)r1r+r,�
<dictcomp>�sz,HTTPAdapter.__getstate__.<locals>.<dictcomp>)�	__attrs__)r1r+)r1r,�__getstate__�szHTTPAdapter.__getstate__cCsHi|_i|_x |��D]\}}t|||�qW|j|j|j|jd�dS)N)rH)rJrC�items�setattrrKrDrErF)r1�staterN�valuer+r+r,�__setstate__�szHTTPAdapter.__setstate__cKs0||_||_||_tf|||dd�|��|_dS)aInitializes a urllib3 PoolManager.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param connections: The number of urllib3 connection pools to cache.
        :param maxsize: The maximum number of connections to save in the pool.
        :param block: Block when no free connections are available.
        :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
        T)�	num_pools�maxsizerH�strictN)rDrErFr�poolmanager)r1ZconnectionsrXrHZpool_kwargsr+r+r,rK�s

zHTTPAdapter.init_poolmanagercKs�||jkr|j|}n||���d�r^t|�\}}t|f|||j|j|jd�|��}|j|<n4|�|�}t	|f||j|j|jd�|��}|j|<|S)a�Return urllib3 ProxyManager for the given proxy.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param proxy: The proxy to return a urllib3 ProxyManager for.
        :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
        :returns: ProxyManager
        :rtype: urllib3.ProxyManager
        �socks)�username�passwordrWrXrH)�
proxy_headersrWrXrH)
rJ�lower�
startswithrr(rDrErFr^r)r1�proxyZproxy_kwargs�managerr\r]r^r+r+r,�proxy_manager_for�s*

zHTTPAdapter.proxy_manager_forcCs�|���d�rn|rnd}|dk	r"|}|s.tt�}|r>tj�|�sLtd�|���d|_	tj�
|�sf||_q�||_nd|_	d|_d|_|r�t
|t�s�|d|_|d|_n||_d|_|jr�tj�|j�s�td	�|j���|jr�tj�|j�s�td
�|j���dS)aAVerify a SSL certificate. This method should not be called from user
        code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param conn: The urllib3 connection object associated with the cert.
        :param url: The requested URL.
        :param verify: Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: The SSL certificate to verify.
        �httpsNTzECould not find a suitable TLS CA certificate bundle, invalid path: {}Z
CERT_REQUIREDZ	CERT_NONErrz9Could not find the TLS certificate file, invalid path: {}z1Could not find the TLS key file, invalid path: {})r_r`rr�os�path�exists�IOError�formatZ	cert_reqs�isdirZca_certsZca_cert_dir�
isinstancerZ	cert_fileZkey_file)r1�conn�urlr7r8Zcert_locr+r+r,�cert_verify�s8


zHTTPAdapter.cert_verifycCs�t�}t|dd�|_tt|di��|_t|j�|_||_|jj|_t	|j
t�r^|j
�d�|_
n|j
|_
t
|j||�||_||_|S)a�Builds a :class:`Response <requests.Response>` object from a urllib3
        response. This should not be called from user code, and is only exposed
        for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`

        :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
        :param resp: The urllib3 response object.
        :rtype: requests.Response
        �statusN�headerszutf-8)rrLZstatus_coderrpr�encoding�raw�reasonrkrm�bytes�decoder�cookiesr4�
connection)r1�req�resp�responser+r+r,�build_response�s

zHTTPAdapter.build_responseNcCsdt||�}|rDt|d�}t|�}|js.td��|�|�}|�|�}nt|�}|��}|j	�|�}|S)a�Returns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        �httpzFPlease check proxy URL. It is malformed and could be missing the host.)
rrr�hostr%rcZconnection_from_urlr�geturlrZ)r1rmr9raZ	proxy_urlrJrl�parsedr+r+r,�get_connection$s	


zHTTPAdapter.get_connectioncCs*|j��x|j��D]}|��qWdS)z�Disposes of any internal state.

        Currently, this closes the PoolManager and any active ProxyManager,
        which closes any pooled connections.
        N)rZ�clearrJ�values)r1rar+r+r,r;?s
zHTTPAdapter.closec	Cs`t|j|�}t|j�j}|o"|dk}d}|rDt|�j��}|�d�}|j}|r\|s\t|j�}|S)a?Obtain the url to use when making the final request.

        If the message is being sent through a HTTP proxy, the full URL has to
        be used. Otherwise, we should only use the path portion of the URL.

        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
        :rtype: str
        rdFr[)rrmr�schemer_r`Zpath_urlr)	r1r4r9rar�Zis_proxied_http_requestZusing_socks_proxyZproxy_schemermr+r+r,�request_urlIs

zHTTPAdapter.request_urlcKsdS)a"Add any headers needed by the connection. As of v2.0 this does
        nothing by default, but is left for overriding by users that subclass
        the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
        :param kwargs: The keyword arguments from the call to send().
        Nr+)r1r4r*r+r+r,�add_headersfszHTTPAdapter.add_headerscCs&i}t|�\}}|r"t||�|d<|S)aReturns a dictionary of the headers to add to any request sent
        through a proxy. This works with urllib3 magic to ensure that they are
        correctly sent to the proxy, rather than in a tunnelled request if
        CONNECT is being used.

        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param proxy: The url of the proxy being used for this request.
        :rtype: dict
        zProxy-Authorization)rr')r1rarpr\r]r+r+r,r^ts

zHTTPAdapter.proxy_headersFTcCs�y|�|j|�}Wn.tk
r@}zt||d��Wdd}~XYnX|�||j||�|�||�}	|j||||||d�|jdkp�d|jk}
t	|t
�r�y|\}}t||d�}Wq�tk
r�}zd�
|�}
t|
��Wdd}~XYq�Xnt	|t�r�nt||d�}�yN|
�s2|j|j|	|j|jdddd|j|d�
}�nt|d	��rD|j}|jtd
�}y�|j|j|	dd�x$|j��D]\}}|�||��qpW|��xN|jD]D}|�tt|��d
d��d��|�d�|�|�|�d��q�W|�d�y|jdd�}Wntk
�r|��}YnXtj |||ddd�}Wn|�!��YnXW�n�t"t#j$fk
�r�}
zt%|
|d��Wdd}
~
XY�nZt&k
�r*}z�t	|j't(��r�t	|j't)��s�t*||d��t	|j't+��r�t,||d��t	|j't-��r�t.||d��t	|j't/��rt0||d��t%||d��Wdd}~XYn�t1k
�rX}zt%||d��Wdd}~XYn�t-k
�r�}zt.|��Wdd}~XYn^t/t2fk
�r�}z:t	|t/��r�t0||d��nt	|t3��r�t4||d��n�Wdd}~XYnX|�5||�S)aSends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple or urllib3 Timeout object
        :param verify: (optional) Either a boolean, in which case it controls whether
            we verify the server's TLS certificate, or a string, in which case it
            must be a path to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        :rtype: requests.Response
        )r4N)r5r6r7r8r9zContent-Length)�connectrGzrInvalid timeout {}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valueF)
�methodrm�bodyrpZredirectZassert_same_host�preload_content�decode_contentZretriesr6�
proxy_pool)r6T)Zskip_accept_encoding�zutf-8s
s0

)�	buffering)�poolrwr�r�)6r�rmrr&rnr�r�r�rprk�tuple�TimeoutSauce�
ValueErrorriZurlopenr�rB�hasattrr�Z	_get_conn�DEFAULT_POOL_TIMEOUTZ
putrequestrRZ	putheaderZ
endheadersr:�hex�len�encodeZgetresponse�	TypeErrorrZfrom_httplibr;r�socket�errorr rrsr	rr!rr#�_ProxyErrorr
�	_SSLErrorrr�
_HTTPErrorrr"r{)r1r4r5r6r7r8r9rl�erm�chunkedr�rG�errryZlow_conn�headerrU�i�rr+r+r,r:�s�

 


zHTTPAdapter.send)N)FNTNN)r<r=r>r?rP�DEFAULT_POOLSIZErI�DEFAULT_POOLBLOCKr0rQrVrKrcrnr{r�r;r�r�r^r:r@r+r+)r2r,rATs$%4%

rA)Cr?�os.pathrer�Zurllib3.poolmanagerrrZurllib3.responserZurllib3.utilrrr�Zurllib3.util.retryrZurllib3.exceptionsrr	r
r�rrr
r�rrrr�rrZmodelsr�compatrr�utilsrrrrrrrZ
structuresrrvr�
exceptionsr r!r"r#r$r%r&Zauthr'Zurllib3.contrib.socksr(�ImportErrorr�r�rIr��objectr.rAr+r+r+r,�<module>	sF$,