HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/site-packages/urllib3/__pycache__/poolmanager.cpython-37.pyc
B

���gfY�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZdd	lmZmZmZdd
lmZmZmZmZddlmZddlmZdd
lmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ej'r�ddl(Z(ddl)m*Z*dddgZ+e�,e-�Z.dZ/dZ0e�1d�Z2Gdd�dej3�Z4dddd�dd�Z5e�6e5e4�e�6e5e4�d�Z7eed�Z8Gd d�de�Z9Gd!d�de9�Z:d"d#dd$�d%d�Z;dS)&�)�annotationsN)�
TracebackType)�urljoin�)�HTTPHeaderDict�RecentlyUsedContainer)�RequestMethods)�ProxyConfig)�HTTPConnectionPool�HTTPSConnectionPool�port_by_scheme)�LocationValueError�
MaxRetryError�ProxySchemeUnknown�URLSchemeUnknown)�BaseHTTPResponse)�_TYPE_SOCKET_OPTIONS)�connection_requires_http_tunnel)�Retry)�Timeout)�Url�	parse_url)�Literal�PoolManager�ProxyManager�proxy_from_url)�key_file�	cert_file�	cert_reqs�ca_certs�ssl_versionZssl_minimum_versionZssl_maximum_version�ca_cert_dir�ssl_context�key_password�server_hostnamei@�_SelfTc@s�eZdZUdZded<ded<ded<ded<d	ed
<ded<d
ed<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<d ed!<ded"<d#ed$<d%ed&<ded'<d(ed)<ded*<ded+<ded,<d-S).�PoolKeyz�
    All known keyword arguments that could be provided to the pool manager, its
    pools, or the underlying connections.

    All custom key schemes should include the fields in this key at a minimum.
    �str�
key_scheme�key_hostz
int | None�key_portzTimeout | float | int | None�key_timeoutzRetry | bool | int | None�key_retrieszbool | None�	key_blockztuple[str, int] | None�key_source_addressz
str | None�key_key_file�key_key_password�
key_cert_file�
key_cert_reqs�key_ca_certszint | str | None�key_ssl_versionzssl.TLSVersion | NoneZkey_ssl_minimum_versionZkey_ssl_maximum_version�key_ca_cert_dirzssl.SSLContext | None�key_ssl_context�key_maxsizez!frozenset[tuple[str, str]] | None�key_headersz
Url | None�
key__proxy�key__proxy_headerszProxyConfig | None�key__proxy_configz_TYPE_SOCKET_OPTIONS | None�key_socket_options�key__socks_optionszbool | str | None�key_assert_hostname�key_assert_fingerprint�key_server_hostname�
key_blocksizeN)�__name__�
__module__�__qualname__�__doc__�__annotations__�rGrG�=/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.pyr&9s:
r&z
type[PoolKey]zdict[str, typing.Any])�	key_class�request_context�returncCs�|��}|d��|d<|d��|d<x4dD],}||kr.||dk	r.t||���||<q.W|�d�}|dk	r|t|�|d<x&t|���D]}|�|�|d|<q�Wx|j	D]}||kr�d||<q�W|�d�dkr�t
|d<|f|�S)a�
    Create a pool key out of a request context dictionary.

    According to RFC 3986, both the scheme and host are case-insensitive.
    Therefore, this function normalizes both before constructing the pool
    key for an HTTPS request. If you wish to change this behaviour, provide
    alternate callables to ``key_fn_by_scheme``.

    :param key_class:
        The class to use when constructing the key. This should be a namedtuple
        with the ``scheme`` and ``host`` keys at a minimum.
    :type  key_class: namedtuple
    :param request_context:
        A dictionary-like object that contain the context for a request.
    :type  request_context: dict

    :return: A namedtuple that can be used as a connection pool key.
    :rtype:  PoolKey
    �scheme�host)�headers�_proxy_headers�_socks_optionsN�socket_options�key_rA)�copy�lower�	frozenset�items�get�tuple�list�keys�pop�_fields�_DEFAULT_BLOCKSIZE)rIrJ�context�key�socket_opts�fieldrGrGrH�_default_key_normalizer_s"

rb)�http�httpscseZdZUdZdZded<dZded<dAdd	d
dd��fd
d�
Zddd�dd�Zddddd�dd�Z	dBdddddd�dd�Z
dd �d!d"�ZdCd$d%d$ddd&�d'd(�Zd)dd*�d+d,�Z
d-d)dd.�d/d0�ZdDdddd1�d2d3�Zdd)d4�d5d6�Zd7d8d9�d:d;�ZdEddd8d
d=d>�d?d@�Z�ZS)FraV
    Allows for arbitrary requests while transparently keeping track of
    necessary connection pools for you.

    :param num_pools:
        Number of connection pools to cache before discarding the least
        recently used pool.

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

    :param \**connection_pool_kw:
        Additional parameters are used to create fresh
        :class:`urllib3.connectionpool.ConnectionPool` instances.

    Example:

    .. code-block:: python

        import urllib3

        http = urllib3.PoolManager(num_pools=2)

        resp1 = http.request("GET", "https://google.com/")
        resp2 = http.request("GET", "https://google.com/mail")
        resp3 = http.request("GET", "https://yahoo.com/")

        print(len(http.pools))
        # 2

    Nz
Url | None�proxyzProxyConfig | None�proxy_config�
�intztyping.Mapping[str, str] | Nonez
typing.Any�None)�	num_poolsrN�connection_pool_kwrKcs4t��|�||_|t|�|_t|_t��|_dS)N)�super�__init__rkr�pools�pool_classes_by_scheme�key_fn_by_schemerS)�selfrjrNrk)�	__class__rGrHrm�s
zPoolManager.__init__r%)rqrKcCs|S)NrG)rqrGrGrH�	__enter__�szPoolManager.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | NonezLiteral[False])�exc_type�exc_val�exc_tbrKcCs|��dS)NF)�clear)rqrtrurvrGrGrH�__exit__�szPoolManager.__exit__r'zdict[str, typing.Any] | Noner
)rLrM�portrJrKcCs||j|}|dkr|j��}|�d�dkr2t|d<xdD]}|�|d�q8W|dkrnxtD]}|�|d�qZW|||f|�S)a�
        Create a new :class:`urllib3.connectionpool.ConnectionPool` based on host, port, scheme, and
        any additional pool keyword arguments.

        If ``request_context`` is provided, it is provided as keyword arguments
        to the pool class used. This method is used to actually create the
        connection pools handed out by :meth:`connection_from_url` and
        companion methods. It is intended to be overridden for customization.
        N�	blocksize)rLrMryrc)rorkrSrWr]r[�SSL_KEYWORDS)rqrLrMryrJ�pool_clsr_�kwrGrGrH�	_new_pool�s



zPoolManager._new_pool)rKcCs|j��dS)z�
        Empty our store of pools and direct them all to close.

        This will not affect in-flight connections, but they will not be
        re-used after completion.
        N)rnrw)rqrGrGrHrwszPoolManager.clearrcz
str | Nonez
int | None)rMryrL�pool_kwargsrKcCsT|std��|�|�}|pd|d<|s:t�|d��d�}||d<||d<|�|�S)a�
        Get a :class:`urllib3.connectionpool.ConnectionPool` based on the host, port, and scheme.

        If ``port`` isn't given, it will be derived from the ``scheme`` using
        ``urllib3.connectionpool.port_by_scheme``. If ``pool_kwargs`` is
        provided, it is merged with the instance's ``connection_pool_kw``
        variable and used to create the new connection pool, if one is
        needed.
        zNo host specified.rcrL�PryrM)r
�_merge_pool_kwargsrrWrT�connection_from_context)rqrMryrLrrJrGrGrH�connection_from_hosts
z PoolManager.connection_from_hostzdict[str, typing.Any])rJrKcCsXd|krt�dt�|�d�|d��}|j�|�}|sBt|��||�}|j||d�S)z�
        Get a :class:`urllib3.connectionpool.ConnectionPool` based on the request context.

        ``request_context`` must at least contain the ``scheme`` key and its
        value must be a key in ``key_fn_by_scheme`` instance variable.
        �strictzdThe 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v2.1.0.rL)rJ)	�warnings�warn�DeprecationWarningr[rTrprWr�connection_from_pool_key)rqrJrL�pool_key_constructor�pool_keyrGrGrHr�1s	
z#PoolManager.connection_from_contextr&)r�rJrKc	Cs`|jj�N|j�|�}|r|S|d}|d}|d}|j||||d�}||j|<WdQRX|S)a
        Get a :class:`urllib3.connectionpool.ConnectionPool` based on the provided pool key.

        ``pool_key`` should be a namedtuple that only contains immutable
        objects. At a minimum it must have the ``scheme``, ``host``, and
        ``port`` fields.
        rLrMry)rJN)rn�lockrWr~)rqr�rJ�poolrLrMryrGrGrHr�Js

z$PoolManager.connection_from_pool_key)�urlrrKcCs t|�}|j|j|j|j|d�S)a�
        Similar to :func:`urllib3.connectionpool.connection_from_url`.

        If ``pool_kwargs`` is not provided and a new pool needs to be
        constructed, ``self.connection_pool_kw`` is used to initialize
        the :class:`urllib3.connectionpool.ConnectionPool`. If ``pool_kwargs``
        is provided, it is used instead. Note that if a new pool does not
        need to be created for the request, the provided ``pool_kwargs`` are
        not used.
        )ryrLr)rr�rMryrL)rqr�r�urGrGrH�connection_from_urlds
zPoolManager.connection_from_url)�overriderKc	CsZ|j��}|rVxF|��D]:\}}|dkrJy
||=WqRtk
rFYqRXq|||<qW|S)a
        Merge a dictionary of override values for self.connection_pool_kw.

        This does not modify self.connection_pool_kw and returns a new dict.
        Any keys in the override dictionary with a value of ``None`` are
        removed from the merged dictionary.
        N)rkrSrV�KeyError)rqr��base_pool_kwargsr_�valuerGrGrHr�vs


zPoolManager._merge_pool_kwargsr�bool)�
parsed_urlrKcCs"|jdkrdSt|j|j|j�S)z�
        Indicates if the proxy requires the complete destination URL in the
        request.  Normally this is only needed when not using an HTTP CONNECT
        tunnel.
        NF)rerrfrL)rqr�rGrGrH�!_proxy_requires_url_absolute_form�s
z-PoolManager._proxy_requires_url_absolute_formTr)�methodr��redirectr}rKcKs�t|�}|jdkr"tjdtdd�|j|j|j|jd�}d|d<d|d<d	|krZ|j|d	<|�	|�rv|j
||f|�}n|j
||jf|�}|o�|��}|s�|St
||�}|jd
kr�d}d|d<t|d	���|d	<|�d
�}	t|	t�s�tj|	|d�}	|	j�rJ|�|��sJ|d	��}
x.|d	D]"}|��|	jk�r|
�|d��qW|
|d	<y|	j||||d�}	Wn(tk
�r�|	j�r�|���|SX|	|d
<||d<t�d||�|��|j
||f|�S)aN
        Same as :meth:`urllib3.HTTPConnectionPool.urlopen`
        with custom cross-host redirect logic and only sends the request-uri
        portion of the ``url``.

        The given ``url`` parameter must be absolute, such that an appropriate
        :class:`urllib3.connectionpool.ConnectionPool` can be chosen for it.
        Na	URLs without a scheme (ie 'https://') are deprecated and will raise an error in a future version of urllib3. To avoid this DeprecationWarning ensure all URLs start with 'https://' or 'http://'. Read more in this issue: https://github.com/urllib3/urllib3/issues/2920�)�category�
stacklevel)ryrLF�assert_same_hostr�rNi/�GET�body�retries)r�)�response�_poolzRedirecting %s -> %s) rrLr�r�r�r�rMryrNr��urlopen�request_uri�get_redirect_locationr�statusrZ_prepare_for_method_changerW�
isinstancer�from_int�remove_headers_on_redirect�is_same_hostrSrTr[�	incrementr�raise_on_redirect�
drain_conn�log�info)rqr�r�r�r}r��connr��redirect_locationr��new_headers�headerrGrGrHr��sX






zPoolManager.urlopen)rgN)N)NrcN)N)T)rBrCrDrErerFrfrmrsrxr~rwr�r�r�r�r�r�r��
__classcell__rGrG)rrrHr�s$
 !cs�eZdZdZd!dddddd	d
ddd
d�
�fdd�
Zd"dddddd��fdd�
Zd#dddd�dd�Zd$ddd	ddd��fdd �
Z�ZS)%ra>
    Behaves just like :class:`PoolManager`, but sends all requests through
    the defined proxy, using the CONNECT method for HTTPS URLs.

    :param proxy_url:
        The URL of the proxy to be used.

    :param proxy_headers:
        A dictionary containing headers that will be sent to the proxy. In case
        of HTTP they are being sent with each request, while in the
        HTTPS/CONNECT case they are sent only once. Could be used for proxy
        authentication.

    :param proxy_ssl_context:
        The proxy SSL context is used to establish the TLS connection to the
        proxy when using HTTPS proxies.

    :param use_forwarding_for_https:
        (Defaults to False) If set to True will forward requests to the HTTPS
        proxy to be made on behalf of the client instead of creating a TLS
        tunnel via the CONNECT method. **Enabling this flag means that request
        and response headers and content will be visible from the HTTPS proxy**
        whereas tunneling keeps request and response headers and content
        private.  IP address, target hostname, SNI, and port are always visible
        to an HTTPS proxy even when this flag is disabled.

    :param proxy_assert_hostname:
        The hostname of the certificate to verify against.

    :param proxy_assert_fingerprint:
        The fingerprint of the certificate to verify against.

    Example:

    .. code-block:: python

        import urllib3

        proxy = urllib3.ProxyManager("https://localhost:3128/")

        resp1 = proxy.request("GET", "https://google.com/")
        resp2 = proxy.request("GET", "https://httpbin.org/")

        print(len(proxy.pools))
        # 1

        resp3 = proxy.request("GET", "https://httpbin.org/")
        resp4 = proxy.request("GET", "https://twitter.com/")

        print(len(proxy.pools))
        # 3

    rgNFr'rhztyping.Mapping[str, str] | Nonezssl.SSLContext | Noner�zNone | str | Literal[False]z
str | Nonez
typing.Anyri)
�	proxy_urlrjrN�
proxy_headers�proxy_ssl_context�use_forwarding_for_https�proxy_assert_hostname�proxy_assert_fingerprintrkrKc	
s�t|t�r&|j�d|j�d|j��}
n|}
t|
�}|jdkrFt|j��|jsft�|jd�}|j	|d�}||_
|pri|_||_t
||||�|_|j
|	d<|j|	d<|j|	d<t�j||f|	�dS)	Nz://�:)rcrdr�)ry�_proxyrO�
_proxy_config)r�r
rLrMryrrrrW�_replacerer�r�r	rfrlrm)
rqr�rjrNr�r�r�r�r�rkZ
str_proxy_urlrery)rrrGrHrm#s*






zProxyManager.__init__rcz
int | Nonezdict[str, typing.Any] | Noner
)rMryrLrrKcs<|dkrt�j||||d�St�j|jj|jj|jj|d�S)Nrd)r)rlr�rerMryrL)rqrMryrLr)rrrGrHr�Ls
z!ProxyManager.connection_from_hostztyping.Mapping[str, str])r�rNrKcCs0ddi}t|�j}|r||d<|r,|�|�|S)z�
        Sets headers needed by proxies: specifically, the Accept and Host
        headers. Only sets headers not provided by the user.
        �Acceptz*/*�Host)r�netloc�update)rqr�rN�headers_r�rGrGrH�_set_proxy_headers\s

zProxyManager._set_proxy_headersTr)r�r�r�r}rKcsRt|�}t|j|j|j�s8|�d|j�}|�||�|d<t�j	||fd|i|��S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rNr�)
rrrerfrLrWrNr�rlr�)rqr�r�r�r}r�rN)rrrGrHr�ms
zProxyManager.urlopen)rgNNNFNN)NrcN)N)T)	rBrCrDrErmr�r�r�r�rGrG)rrrHr�s5&#r'z
typing.Any)r�r}rKcKstfd|i|��S)Nr�)r)r�r}rGrGrHr|s)<�
__future__r�	functools�logging�typingr��typesr�urllib.parser�_collectionsrrZ_request_methodsr�
connectionr	�connectionpoolr
rr�
exceptionsr
rrrr�rZutil.connectionrZ
util.proxyrZ
util.retryrZutil.timeoutrZutil.urlrr�
TYPE_CHECKING�ssl�typing_extensionsr�__all__�	getLoggerrBr�r{r]�TypeVarr%�
NamedTupler&rb�partialrprorrrrGrGrGrH�<module>sH


&<

L