Your IP : 18.119.119.191


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__/connectionpool.cpython-37.pyc

B

��`��@s�ddlmZddlZddlZddlZddlZddlZddlmZddlm	Z
ddlmZm
Z
mZmZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!ddl"m#Z#dd	l$m%Z%dd
l&m'Z'ddl(m)Z)ddl*m+Z+dd
l,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;m<Z<ddl:m=Z>ddl:m?Z?m@Z@e#jAjBZBe�CeD�ZEeF�ZGGdd�deF�ZHejIejJhZKGdd�deHe)�ZLGdd�deL�ZMdd�ZNdd �Z=dS)!�)�absolute_importN)�error)�timeout�)�BaseSSLError�BrokenPipeError�DummyConnection�HTTPConnection�
HTTPException�HTTPSConnection�VerifiedHTTPSConnection�port_by_scheme)
�ClosedPoolError�EmptyPoolError�HeaderParsingError�HostChangedError�InsecureRequestWarning�LocationValueError�
MaxRetryError�NewConnectionError�
ProtocolError�
ProxyError�ReadTimeoutError�SSLError�TimeoutError)�six)�queue)�CertificateError)�RequestMethods)�HTTPResponse)�is_connection_dropped)�connection_requires_http_tunnel)�	LifoQueue)�set_file_position)�assert_header_parsing)�Retry)�Timeout)�Url�_encode_target)�_normalize_host)�get_host�	parse_urlc@sBeZdZdZdZeZd
dd�Zdd�Zdd�Z	d	d
�Z
dd�ZdS)�ConnectionPoola;
    Base class for all connection pools, such as
    :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.

    .. note::
       ConnectionPool.urlopen() does not normalize or percent-encode target URIs
       which is useful if your target server doesn't support percent-encoded
       target URIs.
    NcCs0|std��t||jd�|_|��|_||_dS)NzNo host specified.)�scheme)rr)r-�host�lower�_proxy_host�port)�selfr.r1�r3�G/opt/alt/python37/lib/python3.7/site-packages/urllib3/connectionpool.py�__init__Js

zConnectionPool.__init__cCsdt|�j|j|jfS)Nz%s(host=%r, port=%r))�type�__name__r.r1)r2r3r3r4�__str__RszConnectionPool.__str__cCs|S)Nr3)r2r3r3r4�	__enter__UszConnectionPool.__enter__cCs|��dS)NF)�close)r2�exc_type�exc_val�exc_tbr3r3r4�__exit__XszConnectionPool.__exit__cCsdS)zD
        Close all pooled connections and disable the pool.
        Nr3)r2r3r3r4r:]szConnectionPool.close)N)r7�
__module__�__qualname__�__doc__r-r"�QueueClsr5r8r9r>r:r3r3r3r4r,<s	
r,c
@s�eZdZdZdZeZeZdde	j
dddddddf
dd�Zdd	�Zd!d
d�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zedfdd�Zdd�Zdd�Zdd�Zdddddeddddf
dd �ZdS)"�HTTPConnectionPoola:	
    Thread-safe connection pool for one host.

    :param host:
        Host used for this HTTP Connection (e.g. "localhost"), passed into
        :class:`http.client.HTTPConnection`.

    :param port:
        Port used for this HTTP Connection (None is equivalent to 80), passed
        into :class:`http.client.HTTPConnection`.

    :param strict:
        Causes BadStatusLine to be raised if the status line can't be parsed
        as a valid HTTP/1.0 or 1.1 status line, passed into
        :class:`http.client.HTTPConnection`.

        .. note::
           Only works in Python 2. This parameter is ignored in Python 3.

    :param timeout:
        Socket timeout in seconds for each individual connection. This can
        be a float or integer, which sets the timeout for the HTTP request,
        or an instance of :class:`urllib3.util.Timeout` which gives you more
        fine-grained control over request timeouts. After the constructor has
        been parsed, this is always a `urllib3.util.Timeout` object.

    :param maxsize:
        Number of connections to save that can be reused. More than 1 is useful
        in multithreaded situations. If ``block`` is set to False, more
        connections will be created but they will not be saved once they've
        been used.

    :param block:
        If set to True, no more than ``maxsize`` connections will be used at
        a time. When no free connections are available, the call will block
        until a connection has been released. This is a useful side effect for
        particular multithreaded situations where one does not want to use more
        than maxsize connections per host to prevent flooding.

    :param headers:
        Headers to include with all requests, unless other headers are given
        explicitly.

    :param retries:
        Retry configuration to use by default with requests in this pool.

    :param _proxy:
        Parsed proxy URL, should not be used directly, instead, see
        :class:`urllib3.ProxyManager`

    :param _proxy_headers:
        A dictionary with proxy headers, should not be used directly,
        instead, see :class:`urllib3.ProxyManager`

    :param \**conn_kw:
        Additional parameters are used to create fresh :class:`urllib3.connection.HTTPConnection`,
        :class:`urllib3.connection.HTTPSConnection` instances.
    �httpNFrcKs�t�|||�t�||�||_t|t�s4t�|�}|dkrBtj}||_	||_
|�|�|_||_
|	|_|
pli|_||_xt|�D]}
|j�d�q�Wd|_d|_||_|jr�|j�dg�|j|jd<|j|jd<dS)NrZsocket_options�proxy�proxy_config)r,r5r�strict�
isinstancer&�
from_floatr%�DEFAULTr�retriesrB�pool�blockrE�
proxy_headersrF�xrange�put�num_connections�num_requests�conn_kw�
setdefault)r2r.r1rGr�maxsizerM�headersrK�_proxy�_proxy_headersZ
_proxy_configrS�_r3r3r4r5�s.


zHTTPConnectionPool.__init__cCsR|jd7_t�d|j|j|jp$d�|jf|j|j|jj|jd�|j	��}|S)z9
        Return a fresh :class:`HTTPConnection`.
        rz(Starting new HTTP connection (%d): %s:%sZ80)r.r1rrG)
rQ�log�debugr.r1�
ConnectionClsr�connect_timeoutrGrS)r2�connr3r3r4�	_new_conn�s
zHTTPConnectionPool._new_conncCs�d}y|jj|j|d�}WnBtk
r8t|d��Yn&tjk
r\|jrXt|d��YnX|r�t|�r�t	�
d|j�|��t
|dd�dkr�d}|p�|��S)	a�
        Get a connection. Will return a pooled connection if one is available.

        If no connections are available and :prop:`.block` is ``False``, then a
        fresh connection is returned.

        :param timeout:
            Seconds to wait before giving up and raising
            :class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and
            :prop:`.block` is ``True``.
        N)rMrzPool is closed.z>Pool reached maximum size and no more connections are allowed.z Resetting dropped connection: %sZ	auto_openrr)rL�getrM�AttributeErrorrr�Emptyrr rZr[r.r:�getattrr_)r2rr^r3r3r4�	_get_conn�s"zHTTPConnectionPool._get_conncCs\y|jj|dd�dStk
r(Yn$tjk
rJt�d|j�YnX|rX|��dS)a�
        Put a connection back into the pool.

        :param conn:
            Connection object for the current host and port as returned by
            :meth:`._new_conn` or :meth:`._get_conn`.

        If the pool is already full, the connection is closed and discarded
        because we exceeded maxsize. If connections are discarded frequently,
        then maxsize should be increased.

        If the pool is closed, then the connection will be closed and discarded.
        F)rMNz2Connection pool is full, discarding connection: %s)	rLrPrar�FullrZ�warningr.r:)r2r^r3r3r4�	_put_connszHTTPConnectionPool._put_conncCsdS)zU
        Called right before a request is made, after the socket is created.
        Nr3)r2r^r3r3r4�_validate_conn6sz!HTTPConnectionPool._validate_conncCsdS)Nr3)r2r^r3r3r4�_prepare_proxy<sz!HTTPConnectionPool._prepare_proxycCs2|tkr|j��St|t�r$|��St�|�SdS)z:Helper that always returns a :class:`urllib3.util.Timeout`N)�_Defaultr�clonerHr&rI)r2rr3r3r4�_get_timeout@s


zHTTPConnectionPool._get_timeoutcCsjt|t�rt||d|��t|d�r>|jtkr>t||d|��dt|�ksVdt|�krft||d|��dS)zAIs the error actually a timeout? Will raise a ReadTimeout or passz!Read timed out. (read timeout=%s)�errnoz	timed outzdid not complete (read)N)rH�
SocketTimeoutr�hasattrrm�_blocking_errnos�str)r2�err�url�
timeout_valuer3r3r4�_raise_timeoutLs
z!HTTPConnectionPool._raise_timeoutc

Ksn|jd7_|�|�}|��|j|_y|�|�Wn:ttfk
rp}z|j|||jd��Wdd}~XYnXy*|r�|j	||f|�n|j
||f|�WnLtk
r�Yn:tk
r�}z|j
t
jt
jt
jhkr؂Wdd}~XYnX|j}	t|dd��rB|	dk�rt||d|	��|	tjk�r6|j�t���n|j�|	�yjy|jdd�}
WnTtk
�r�y|��}
Wn0tk
�r�}zt�|d�Wdd}~XYnXYnXWn<tttfk
�r�}z|j|||	d��Wdd}~XYnXt|d	d
�}t �!d|j"|j#|j$||||
j%|
j&�	yt'|
j(�Wn@t)tfk
�rh}zt j*d|�+|�|dd
�Wdd}~XYnX|
S)a
        Perform a request on a given urllib connection object taken from our
        pool.

        :param conn:
            a connection from one of our connection pools

        :param timeout:
            Socket timeout in seconds for the request. This can be a
            float or integer, which will set the same timeout value for
            the socket connect and the socket read, or an instance of
            :class:`urllib3.util.Timeout`, which gives you more fine-grained
            control over your timeouts.
        r)rrrsrtN�sockrz!Read timed out. (read timeout=%s)T)�	bufferingZ
_http_vsn_strzHTTP/?z%s://%s:%s "%s %s %s" %s %sz$Failed to parse headers (url=%s): %s)�exc_info),rRrlZ
start_connectr]rrhrnrruZrequest_chunked�requestr�IOErrorrmZEPIPEZ	ESHUTDOWNZ
EPROTOTYPE�read_timeoutrcrr&�DEFAULT_TIMEOUTrv�
settimeout�socket�getdefaulttimeoutZgetresponse�	TypeError�
BaseExceptionrZ
raise_from�SocketErrorrZr[r-r.r1�status�lengthr$�msgrrf�
_absolute_url)
r2r^�methodrsr�chunkedZhttplib_request_kw�timeout_obj�er{�httplib_responseZhttp_versionZhper3r3r4�
_make_requestesx


(z HTTPConnectionPool._make_requestcCst|j|j|j|d�jS)N)r-r.r1�path)r'r-r.r1rs)r2r�r3r3r4r��sz HTTPConnectionPool._absolute_urlcCsZ|jdkrdS|jd}|_y"x|jdd�}|r |��q WWntjk
rTYnXdS)zD
        Close all pooled connections and disable the pool.
        NF)rM)rLr`r:rrb)r2Zold_poolr^r3r3r4r:�s
zHTTPConnectionPool.closecCsx|�d�rdSt|�\}}}|dk	r0t||d�}|jrF|sFt�|�}n|js^|t�|�kr^d}|||f|j|j|jfkS)zj
        Check if the given ``url`` is a member of the same host as this
        connection pool.
        �/TN)r-)�
startswithr*r)r1r
r`r-r.)r2rsr-r.r1r3r3r4�is_same_host�s

zHTTPConnectionPool.is_same_hostTc
Kst|�}|j}|dkr|j}t|t�s8tj|||jd�}|
dkrL|
�dd�}
|rf|�|�sft	|||��|�
d�r�t�t
|��}nt�|j�}d}|
}t|j|j|�}|s�|��}|�|j�d}d}t||�}�zzy�|�|�}|j|	d�}|j|_|jdk	�o
t|dd�}|�r"|�r"|�|�|j|||||||d	�}|
�sD|nd}||
d
<|jj|f|||d�|
��}d}Wn�tk
�r�d}d}�Yn�t t!t"t#t$t%t&fk
�rF}z�d}t|t$t&f��r�t%|�}n>t|t"t'f��r�|j�r�t(d|�}nt|t"t!f��rt#d
|�}|j)||||t*�+�dd�}|�,�|}Wdd}~XYnXWd|�sd|�o^|�-�}d}|�rt|�.|�X|�s�t/�0d|||�|j1|||||||f||	|
||d�|
��S|�o�|�2�}|�rd|j3dk�r�d}y|j)||||d�}Wn(t4k
�r|j5�r|�6��|SX|�6�|�7|�t/�8d||�|j1||||f|||||	|
||d�|
��St9|�:d��}|�;||j3|��ry|j)||||d�}Wn(t4k
�r�|j<�r�|�6��|SX|�6�|�,|�t/�8d|�|j1||||f|||||	|
||d�|
��S|S)a+
        Get a connection from the pool and perform an HTTP request. This is the
        lowest level call for making a request, so you'll need to specify all
        the raw details.

        .. note::

           More commonly, it's appropriate to use a convenience method provided
           by :class:`.RequestMethods`, such as :meth:`request`.

        .. note::

           `release_conn` will only behave as expected if
           `preload_content=False` because we want to make
           `preload_content=False` the default behaviour someday soon without
           breaking backwards compatibility.

        :param method:
            HTTP request method (such as GET, POST, PUT, etc.)

        :param url:
            The URL to perform the request on.

        :param body:
            Data to send in the request body, either :class:`str`, :class:`bytes`,
            an iterable of :class:`str`/:class:`bytes`, or a file-like object.

        :param headers:
            Dictionary of custom headers to send, such as User-Agent,
            If-None-Match, etc. If None, pool headers are used. If provided,
            these headers completely replace any pool-specific headers.

        :param retries:
            Configure the number of retries to allow before raising a
            :class:`~urllib3.exceptions.MaxRetryError` exception.

            Pass ``None`` to retry until you receive a response. Pass a
            :class:`~urllib3.util.retry.Retry` object for fine-grained control
            over different types of retries.
            Pass an integer number to retry connection errors that many times,
            but no other types of errors. Pass zero to never retry.

            If ``False``, then retries are disabled and any exception is raised
            immediately. Also, instead of raising a MaxRetryError on redirects,
            the redirect response will be returned.

        :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.

        :param redirect:
            If True, automatically handle redirects (status codes 301, 302,
            303, 307, 308). Each redirect counts as a retry. Disabling retries
            will disable redirect, too.

        :param assert_same_host:
            If ``True``, will make sure that the host of the pool requests is
            consistent else will raise HostChangedError. When ``False``, you can
            use the pool on an HTTP proxy and request foreign hosts.

        :param timeout:
            If specified, overrides the default timeout for this one
            request. It may be a float (in seconds) or an instance of
            :class:`urllib3.util.Timeout`.

        :param pool_timeout:
            If set and the pool is set to block=True, then this method will
            block for ``pool_timeout`` seconds and raise EmptyPoolError if no
            connection is available within the time period.

        :param release_conn:
            If False, then the urlopen call will not release the connection
            back into the pool once a response is received (but will release if
            you read the entire contents of the response such as when
            `preload_content=True`). This is useful if you're not preloading
            the response's content immediately. You will need to call
            ``r.release_conn()`` on the response ``r`` to return the connection
            back into the pool. If None, it takes the value of
            ``response_kw.get('preload_content', True)``.

        :param chunked:
            If True, urllib3 will send the body using chunked transfer
            encoding. Otherwise, urllib3 will send the body using the standard
            content-length form. Defaults to False.

        :param int body_pos:
            Position to seek to in file-like body in the event of a retry or
            redirect. Typically this won't need to be set because urllib3 will
            auto-populate the value when needed.

        :param \**response_kw:
            Additional parameters are passed to
            :meth:`urllib3.response.HTTPResponse.from_httplib`
        N)�redirect�defaultZpreload_contentTr�F)rrv)r�bodyrVr�Zrequest_method)rL�
connectionrKzCannot connect to proxy.zConnection aborted.�)r�_poolZ_stacktracez1Retrying (%r) after connection broken by '%r': %s)r�pool_timeout�release_connr��body_posi/ZGET)�responser�zRedirecting %s -> %s)rKr��assert_same_hostrr�r�r�r�zRetry-Afterz	Retry: %s)=r+r-rVrHr%Zfrom_intrKr`r�rr�rZ
ensure_strr(rsr!rErF�copy�updaterNr#rlrdr]rrcrir��ResponseClsZfrom_httplibrrr
r�rrrrrrZ	increment�sysrx�sleepr:rgrZrf�urlopenZget_redirect_locationr�rZraise_on_redirectZ
drain_connZsleep_for_retryr[�bool�	getheaderZis_retryZraise_on_status)r2r�rsr�rVrKr�r�rr�r�r�r�Zresponse_kw�
parsed_urlZdestination_schemer^Zrelease_this_connZhttp_tunnel_requiredrrZ
clean_exitr�Zis_new_proxy_connr�Z
response_connr�r�Zredirect_locationZhas_retry_afterr3r3r4r�s(m








zHTTPConnectionPool.urlopen)N)r7r?r@rAr-r	r\rr�r&r|r5r_rdrgrhrirlrurjr�r�r:r�r�r3r3r3r4rChsF:*
'vrCcspeZdZdZdZeZddejdddddddddddddddfdd�Z	dd	�Z
d
d�Zdd
�Z�fdd�Z
�ZS)�HTTPSConnectionPoola
    Same as :class:`.HTTPConnectionPool`, but HTTPS.

    :class:`.HTTPSConnection` uses one of ``assert_fingerprint``,
    ``assert_hostname`` and ``host`` in this order to verify connections.
    If ``assert_hostname`` is False, no verification is done.

    The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs``,
    ``ca_cert_dir``, ``ssl_version``, ``key_password`` are only used if :mod:`ssl`
    is available and are fed into :meth:`urllib3.util.ssl_wrap_socket` to upgrade
    the connection socket into an SSL socket.
    �httpsNFrcKs\tj||||||||||	|
f|�||_||_|
|_||_||_||_||_||_	||_
dS)N)rCr5�key_file�	cert_file�	cert_reqs�key_password�ca_certs�ca_cert_dir�ssl_version�assert_hostname�assert_fingerprint)r2r.r1rGrrUrMrVrKrWrXr�r�r�r�r�r�r�r�r�rSr3r3r4r5rs,zHTTPSConnectionPool.__init__c
Cs@t|t�r<|j|j|j|j|j|j|j|j	|j
d�|j|_|S)z�
        Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket`
        and establish the tunnel if proxy is used.
        )r�r�r�r�r�r�r�r�)rHrZset_certr�r�r�r�r�r�r�r�r�)r2r^r3r3r4�
_prepare_conn�s

z!HTTPSConnectionPool._prepare_conncCs2|�|j|j|j�|jjdkr&d|_|��dS)z�
        Establishes a tunnel connection through HTTP CONNECT.

        Tunnel connection is established early because otherwise httplib would
        improperly set Host: header to proxy's IP:port.
        r�TN)Z
set_tunnelr0r1rNrEr-Ztls_in_tls_required�connect)r2r^r3r3r4ri�sz"HTTPSConnectionPool._prepare_proxyc
Cs�|jd7_t�d|j|j|jp$d�|jr8|jtkr@td��|j}|j}|jdk	rf|jj}|jj}|jf|||j	j
|j|j|j
|jd�|j��}|�|�S)zF
        Return a fresh :class:`http.client.HTTPSConnection`.
        rz)Starting new HTTPS connection (%d): %s:%sZ443zCCan't connect to HTTPS URL because the SSL module is not available.N)r.r1rrGr�r�r�)rQrZr[r.r1r\rrrErr]rGr�r�r�rSr�)r2Zactual_hostZactual_portr^r3r3r4r_�s0

zHTTPSConnectionPool._new_conncs@tt|��|�t|dd�s$|��|js<t�d|jt	�dS)zU
        Called right before a request is made, after the socket is created.
        rvNz�Unverified HTTPS request is being made to host '%s'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings)
�superr�rhrcr�Zis_verified�warnings�warnr.r)r2r^)�	__class__r3r4rh�sz"HTTPSConnectionPool._validate_conn)r7r?r@rAr-rr\r&r|r5r�rir_rh�
__classcell__r3r3)r�r4r�as2$r�cKsRt|�\}}}|pt�|d�}|dkr:t|fd|i|��St|fd|i|��SdS)a�
    Given a url, return an :class:`.ConnectionPool` instance of its host.

    This is a shortcut for not having to parse out the scheme, host, and port
    of the url before creating an :class:`.ConnectionPool` instance.

    :param url:
        Absolute URL string that must include the scheme. Port is optional.

    :param \**kw:
        Passes additional parameters to the constructor of the appropriate
        :class:`.ConnectionPool`. Useful for specifying things like
        timeout, maxsize, headers, etc.

    Example::

        >>> conn = connection_from_url('http://google.com/')
        >>> r = conn.request('GET', '/')
    �Pr�r1N)r*r
r`r�rC)rs�kwr-r.r1r3r3r4�connection_from_urls
r�cCs.t||�}|�d�r*|�d�r*|dd�}|S)z?
    Normalize hosts for comparisons and use with sockets.
    �[�]r���)�normalize_hostr��endswith)r.r-r3r3r4r)s
r))O�
__future__rrm�loggingr~r�r�rr�rrnr�rrrr	r
rrr
�
exceptionsrrrrrrrrrrrrr�packagesrZpackages.six.movesrZpackages.ssl_match_hostnamerryrr�rZutil.connectionr Z
util.proxyr!Z
util.queuer"Zutil.requestr#Z
util.responser$Z
util.retryr%Zutil.timeoutr&Zutil.urlr'r(r)r�r*r+ZmovesrO�	getLoggerr7rZ�objectrjr,�EAGAIN�EWOULDBLOCKrprCr�r�r3r3r3r4�<module>sN(
<
)~ 

?>