Your IP : 3.148.115.40


Current Path : /proc/self/root/lib/python3.6/site-packages/requests/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/requests/__pycache__/adapters.cpython-36.pyc

3

��{g7q�@sRdZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddl
mZ
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3m4Z4m5Z5mZmZm6Z6m7Z7m8Z8m9Z9ddl:m;Z;yddl<m=Z=Wne>k
�r�dd�Z=YnXdZ?d Z@dZAdZBy ddlCZCe�ZDeDjEe(e'��Wne>k
�r�dZDYnXd!d"ejFeGejHfeId#�d$d%�ZJd&d!d"d'd(d)�d*d+�ZKGd,d-�d-eL�ZMGd.d/�d/eM�ZNdS)0z�
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)�create_urllib3_context)�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,�/usr/lib/python3.6/adapters.pyr)0sr)F�
zbool | str | Nonez#typing.Tuple[str, str] | str | None)�verify�client_cert�poolmanager_kwargs�returncCs,|jd�}|dko&tdk	o&|o&|dk}|S)N�ssl_contextT)�get�_preloaded_ssl_context)r/r0r1Zhas_poolmanager_ssl_contextZshould_use_default_ssl_contextr,r,r-�_should_use_default_contextEs
r6ZPreparedRequestrz<(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any]))�requestr/r0�poolmanagerr2cCs�i}i}t|j�}|jj�}|j}t|di�}	d}
d}|dkrDd}
n6t|||	�rZt|d<n |dkrltt	�}nt
|t�rz|}|dk	r�tj
j|�s�||d<n||d<|
|d	<|dk	r�t
|t�r�t|�d
kr�|d|d<|d
|d<n||d<||j|d�}||fS)NZconnection_pool_kw�
CERT_REQUIREDF�	CERT_NONEr3T�ca_certs�ca_cert_dir�	cert_reqs�r�	cert_filer�key_file)�scheme�host�port)r�urlrA�lowerrC�getattrr6r5rr�
isinstance�str�os�path�isdir�tuple�lenZhostname)r7r/r0r8�host_params�pool_kwargsZparsed_request_urlrArCr1r=�cert_locr,r,r-�_urllib3_request_contextVs<





rQcs2eZdZdZ�fdd�Zddd�Zd	d
�Z�ZS)�BaseAdapterzThe Base Transport Adaptercstt|�j�dS)N)�superrR�__init__)�self)�	__class__r,r-rT�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)rUr7�stream�timeoutr/�cert�proxiesr,r,r-�send�szBaseAdapter.sendcCst�dS)z!Cleans up adapter specific items.N)rW)rUr,r,r-�close�szBaseAdapter.close)FNTNN)�__name__�
__module__�__qualname__�__doc__rTr\r]�
__classcell__r,r,)rVr-rR�s

rRcs�eZdZdZdddddgZeeeef�fdd�	Zd	d
�Z	dd�Z
efd
d�Zdd�Zdd�Z
dd�Zd(dd�Zd)dd�Zd*dd�Zdd�Zdd�Zd d!�Zd"d#�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tj|�|_i|_i|_tt|�j�||_	||_
||_|j|||d�dS)NrF)�read)�block)
�DEFAULT_RETRIESrrdZfrom_intre�
proxy_managerrSrcrTrfrgrh�init_poolmanager)rUZpool_connectionsZpool_maxsizerdZ
pool_block)rVr,r-rT�szHTTPAdapter.__init__cs�fdd��jD�S)Ncsi|]}t�|d�|�qS)N)rF)�.0�attr)rUr,r-�
<dictcomp>�sz,HTTPAdapter.__getstate__.<locals>.<dictcomp>)�	__attrs__)rUr,)rUr-�__getstate__�szHTTPAdapter.__getstate__cCsHi|_i|_x |j�D]\}}t|||�qW|j|j|j|jd�dS)N)rj)rlre�items�setattrrmrfrgrh)rU�statero�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�maxsizerj�strictN)rfrgrhrr8)rUZconnectionsryrjrOr,r,r-rm�s

zHTTPAdapter.init_poolmanagercKs�||jkr|j|}n||j�jd�r^t|�\}}t|f|||j|j|jd�|��}|j|<n4|j|�}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�passwordrxryrj)�
proxy_headersrxryrj)
rlrE�
startswithrr)rfrgrhr~r)rU�proxyZproxy_kwargsZmanagerr|r}r~r,r,r-�proxy_manager_for�s*

zHTTPAdapter.proxy_manager_forcCs�|j�jd�rZ|rZd|_|dk	rl|}tjj|�s>td|����tjj|�sR||_ql||_	nd|_d|_d|_	|r�t
|t�s�|d|_|d|_
n||_d|_
|jr�tjj|j�r�td	j|j���|j
r�tjj|j
�r�td
j|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.
        �httpsr9TzCCould not find a suitable TLS CA certificate bundle, invalid path: r:Nrrz9Could not find the TLS certificate file, invalid path: {}z1Could not find the TLS key file, invalid path: {})rErr=rIrJ�exists�OSErrorrKr;r<rGrr?r@�IOError�format)rU�connrDr/rZrPr,r,r-�cert_verifys2


zHTTPAdapter.cert_verifycCs�t�}t|dd�|_tt|di��|_t|j�|_||_|jj|_t	|j
t�r^|j
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
        ZstatusN�headerszutf-8)rrFZstatus_coderr�r�encoding�raw�reasonrGrD�bytes�decoder �cookiesr7�
connection)rUZreq�respZresponser,r,r-�build_responseLs

zHTTPAdapter.build_responseNcCst||||j�S)a�	Build the PoolKey attributes used by urllib3 to return a connection.
        This looks at the PreparedRequest, the user-specified verify value,
        and the value of the cert parameter to determine what PoolKey values
        to use to select a connection from a given urllib3 Connection Pool.
        The SSL related pool key arguments are not consistently set. As of
        this writing, use the following to determine what keys may be in that
        dictionary:
        * If ``verify`` is ``True``, ``"ssl_context"`` will be set and will be the
          default Requests SSL Context
        * If ``verify`` is ``False``, ``"ssl_context"`` will not be set but
          ``"cert_reqs"`` will be set
        * If ``verify`` is a string, (i.e., it is a user-specified trust bundle)
          ``"ca_certs"`` will be set if the string is not a directory recognized
          by :py:func:`os.path.isdir`, otherwise ``"ca_certs_dir"`` will be
          set.
        * If ``"cert"`` is specified, ``"cert_file"`` will always be set. If
          ``"cert"`` is a tuple with a second item, ``"key_file"`` will also
          be present
        To override these settings, one may subclass this class, call this
        method and use the above logic to change parameters as desired. For
        example, if one wishes to use a custom :py:class:`ssl.SSLContext` one
        must both set ``"ssl_context"`` and based on what else they require,
        alter the other keys to ensure the desired behaviour.
        :param request:
            The PreparedReqest being sent over the connection.
        :type request:
            :class:`~requests.models.PreparedRequest`
        :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:
            (optional) Any user-provided SSL certificate for client
            authentication (a.k.a., mTLS). This may be a string (i.e., just
            the path to a file which holds both certificate and key) or a
            tuple of length 2 with the certificate file path and key file
            path.
        :returns:
            A tuple of two dictionaries. The first is the "host parameters"
            portion of the Pool Key including scheme, hostname, and port. The
            second is a dictionary of SSLContext related parameters.
        )rQr8)rUr7r/rZr,r,r-�$build_connection_pool_key_attributesqs+z0HTTPAdapter.build_connection_pool_key_attributescCs�t|j|�}y|j|||�\}}Wn.tk
rP}zt||d��WYdd}~XnX|r�t|d�}t|�}	|	jsvtd��|j	|�}
|
j
f|d|i��}n|jj
f|d|i��}|S)apReturns a urllib3 connection for the given request and TLS settings.
        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>` object to be sent
            over the connection.
        :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 proxies:
            (optional) The proxies dictionary to apply to the request.
        :param cert:
            (optional) Any user-provided SSL certificate to be used for client
            authentication (a.k.a., mTLS).
        :rtype:
            urllib3.ConnectionPool
        )r7N�httpzFPlease check proxy URL. It is malformed and could be missing the host.rO)rrDr��
ValueErrorr'rrrBr&r�Zconnection_from_hostr8)rUr7r/r[rZr�rNrO�e�	proxy_urlrlr�r,r,r-�get_connection_with_tls_context�s(

z+HTTPAdapter.get_connection_with_tls_contextcCsdt||�}|rDt|d�}t|�}|js.td��|j|�}|j|�}nt|�}|j�}|j	j|�}|S)aDEPRECATED: Users should move to `get_connection_with_tls_context`
        for all subclasses of HTTPAdapter using Requests>=2.32.2.
        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
        r�zFPlease check proxy URL. It is malformed and could be missing the host.)
rrrrBr&r�Zconnection_from_urlrZgeturlr8)rUrDr[r�r�rlr�Zparsedr,r,r-�get_connection�s


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

        Currently, this closes the PoolManager and any active ProxyManager,
        which closes any pooled connections.
        N)r8�clearrl�values)rUr�r,r,r-r]�s
zHTTPAdapter.closec	Csbt|j|�}t|j�j}|o"|dk}d}|rDt|�jj�}|jd�}|j}|r^|r^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
        r�Fr{)rrDrrArErZpath_urlr)	rUr7r[r�rAZis_proxied_http_requestZusing_socks_proxyZproxy_schemerDr,r,r-�request_url�s


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,)rUr7r+r,r,r-�add_headerss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()rUr�r�r|r}r,r,r-r~s

zHTTPAdapter.proxy_headersFTc7Cs�y|j||||d�}Wn.tk
rD}zt||d��WYdd}~XnX|j||j||�|j||�}	|j||||||d�|jdkp�d|jk}
t	|t
�r�y|\}}t||d�}Wn4tk
r�}zdj
|�}
t|
��WYdd}~XnXnt	|t�r�nt||d�}�yN|
�s6|j|j|	|j|jdddd|j|d	�
}�nt|d
��rH|j}|jtd�}y�|j|j|	dd
�x$|jj�D]\}}|j||��qtW|j�xN|jD]D}|jtt|��dd�jd��|jd�|j|�|jd��q�W|jd�y|jdd�}Wntk
�r|j�}YnXtj |||ddd�}Wn|j!��YnXW�n�t"t#j$fk
�r�}
zt%|
|d��WYdd}
~
X�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��WYdd}~Xn�t1k
�r\}zt%||d��WYdd}~Xn�t-k
�r�}zt.|��WYdd}~Xn^t/t2fk
�r�}z<t	|t/��r�t0||d��nt	|t3��r�t4||d��n�WYdd}~XnX|j5||�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
        )r[rZ)r7N)rXrYr/rZr[zContent-Length)�connectrizrInvalid timeout {}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valueF)
�methodrD�bodyr�ZredirectZassert_same_host�preload_content�decode_contentZretriesrY�
proxy_pool)rYT)Zskip_accept_encodingr>zutf-8s
s0

)�	buffering)Zpoolr�r�r�)6r�rr'r�rDr�r�r�r�rGrL�TimeoutSaucer�r�Zurlopenr�rd�hasattrr�Z	_get_conn�DEFAULT_POOL_TIMEOUTZ
putrequestrsZ	putheaderZ
endheadersr\�hexrM�encodeZgetresponse�	TypeErrorrZfrom_httplibr]r�socket�errorr!rr�r
r
r"rr$�_ProxyErrorr�	_SSLErrorrr	�
_HTTPErrorrr#r�)rUr7rXrYr/rZr[r�r�rDZchunkedr�ri�errr�Zlow_conn�headerrv�i�rr,r,r-r\5s�

 


zHTTPAdapter.send)N)NN)N)FNTNN)r^r_r`rarq�DEFAULT_POOLSIZErk�DEFAULT_POOLBLOCKrTrrrwrmr�r�r�r�r�r�r]r�r�r~r\rbr,r,)rVr-rc�s(%3%
-
/

rc)OraZos.pathrIr�ZtypingZurllib3.poolmanagerrrZurllib3.responserZurllib3.utilrrr�Zurllib3.util.retryrZurllib3.util.ssl_rZurllib3.exceptionsr	r
rr�rr
rr�rrrr�rrZmodelsr�compatrrZutilsrrrrrrrZ
structuresrr�r �
exceptionsr!r"r#r$r%r&r'Zauthr(Zurllib3.contrib.socksr)�ImportErrorr�r�rkr�Zsslr5Zload_verify_locationsZDictrHZAny�boolr6rQ�objectrRrcr,r,r,r-�<module>	sj$,
*

?>