관리-도구
편집 파일: poolmanager.cpython-39.pyc
a ����[��f3M����������������������@���s6��d�dl�mZ�d�dlZd�dlZd�dlZddlmZ�ddlmZm Z m Z �ddlmZm Z mZmZmZ�ddlmZ�ddlmZ�dd lmZ�dd lmZ�ddlmZ�ddlmZ�g�d �Ze�e�Z dZ!dZ"e�#de"�Z$dZ%e�#de%�Z&dd��Z'e�(e'e$�e�(e'e$�d�Z)ee d�Z*G�dd��de�Z+G�dd��de+�Z,dd��Z-dS�)�����)�absolute_importN����)�RecentlyUsedContainer)�HTTPConnectionPool�HTTPSConnectionPool�port_by_scheme)�LocationValueError� MaxRetryError�ProxySchemeUnknown�ProxySchemeUnsupported�URLSchemeUnknown)�six)�urljoin)�RequestMethods)�connection_requires_http_tunnel)�Retry)� parse_url)�PoolManager�ProxyManager�proxy_from_url)Zkey_fileZ cert_fileZ cert_reqsZca_certsZssl_versionZca_cert_dir�ssl_contextZkey_password)Z key_schemeZkey_hostZkey_portZkey_timeoutZkey_retriesZ key_strictZ key_blockZkey_source_addressZkey_key_fileZkey_key_passwordZ key_cert_fileZ key_cert_reqsZkey_ca_certsZkey_ssl_versionZkey_ca_cert_dirZkey_ssl_contextZkey_maxsizeZkey_headersZ key__proxyZkey__proxy_headersZkey__proxy_configZkey_socket_optionsZkey__socks_optionsZkey_assert_hostnameZkey_assert_fingerprintZkey_server_hostname�PoolKey)r����use_forwarding_for_https�ProxyConfigc�����������������C���s����|����}|d����|d<�|d����|d<�dD�],}||v�r,||�dur,t||�����||<�q,|�d�}|durxt|�|d<�t|����D�]}|�|�|d|�<�q�|�j D�]}||vr�d||<�q�|�f�i�|��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_headersZ_socks_optionsNZsocket_optionsZkey_) �copy�lower� frozenset�items�get�tuple�list�keys�pop�_fields)Z key_class�request_context�context�keyZsocket_optsZfield��r+����C/usr/lib/python3.9/site-packages/pip/_vendor/urllib3/poolmanager.py�_default_key_normalizerN���s���� r-�����http�httpsc�������������������@���s����e�Zd�ZdZdZdZd dd�Zdd��Zdd ��Zd!d d�Z dd ��Z d"dd�Zdd��Zd#dd�Z d$dd�Zdd��Zdd��Zdd��Zd%dd�ZdS�)&r���a$�� 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:: >>> manager = PoolManager(num_pools=2) >>> r = manager.request('GET', 'http://google.com/') >>> r = manager.request('GET', 'http://google.com/mail') >>> r = manager.request('GET', 'http://yahoo.com/') >>> len(manager.pools) 2 N� ���c�����������������K���s8���t��|�|��||�_t|dd��d�|�_t|�_t���|�_d�S�)Nc�����������������S���s���|�����S��N)�close)�pr+���r+���r,����<lambda>���������z&PoolManager.__init__.<locals>.<lambda>)Zdispose_func)r����__init__�connection_pool_kwr����pools�pool_classes_by_scheme�key_fn_by_schemer���)�self� num_poolsr���r8���r+���r+���r,���r7�������s ����zPoolManager.__init__c�����������������C���s���|�S�r2���r+����r<���r+���r+���r,���� __enter__����s����zPoolManager.__enter__c�����������������C���s���|������dS�)NF)�clear)r<����exc_typeZexc_valZexc_tbr+���r+���r,����__exit__����s����zPoolManager.__exit__c�����������������C���sb���|�j�|�}|du�r|�j���}dD�]}|�|d��q |dkrPtD�]}|�|d��q>|||fi�|��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)r���r����portr/���)r:���r8���r���r&����SSL_KEYWORDS)r<���r���r���rC���r(���Zpool_clsr*����kwr+���r+���r,���� _new_pool����s���� zPoolManager._new_poolc�����������������C���s���|�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)r9���r@���r>���r+���r+���r,���r@�������s����zPoolManager.clearr/���c�����������������C���sT���|st�d��|��|�}|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.r/���r����P���rC���r���)r����_merge_pool_kwargsr���r"���r����connection_from_context)r<���r���rC���r����pool_kwargsr(���r+���r+���r,����connection_from_host����s���� z PoolManager.connection_from_hostc�����������������C���s:���|d�����}|�j�|�}|s$t|��||�}|�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. r����r(���)r���r;���r"���r����connection_from_pool_key)r<���r(���r���Zpool_key_constructor�pool_keyr+���r+���r,���rI�������s����z#PoolManager.connection_from_contextc�����������������C���s����|�j�j�f�|�j��|�}|r,|W��d����S�|d�}|d�}|d�}|�j||||d�}||�j�|<�W�d����n1�st0����Y��|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. Nr���r���rC���rL���)r9����lockr"���rF���)r<���rN���r(���Zpoolr���r���rC���r+���r+���r,���rM�����s���� (z$PoolManager.connection_from_pool_keyc�����������������C���s ���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. )rC���r���rJ���)r���rK���r���rC���r���)r<����urlrJ����ur+���r+���r,����connection_from_url��s�����zPoolManager.connection_from_urlc�������������� ���C���sT���|�j����}|rP|���D�]8\}}|du�rFz ||=�W�qN�tyB���Y�qN0�q|||<�q|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)r8���r���r!����KeyError)r<����overrideZbase_pool_kwargsr*����valuer+���r+���r,���rH���.��s���� zPoolManager._merge_pool_kwargsc�����������������C���s"���|�j�du�rdS�t|�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)�proxyr����proxy_configr���)r<���Z parsed_urlr+���r+���r,����!_proxy_requires_url_absolute_formB��s ���� �z-PoolManager._proxy_requires_url_absolute_formc�����������������C���s@���|�j�du�s|dkrdS�|�j�jdkr&dS�tjr<|�jjs<td��dS�)z� Validates that were not attempting to do TLS in TLS connections on Python2 or with unsupported SSL implementations. Nr0���zfContacting HTTPS destinations through HTTPS proxies 'via CONNECT tunnels' is not supported in Python 2)rV���r���r ���ZPY2rW���r���r���)r<���Z url_schemer+���r+���r,����$_validate_proxy_scheme_url_selectionO��s�����z0PoolManager._validate_proxy_scheme_url_selectionTc�����������������K���s���t�|�}|��|j��|�j|j|j|jd�}d|d<�d|d<�d|vrP|�j���|d<�|��|�rp|j ||fi�|��}n|j ||j fi�|��}|o�|���}|s�|S�t||�}|j dkr�d}|�d�} t| t�s�tj| |d �} | j�r"|�|��s"tt�|d���} | D�]"}|���| jv�r�|d��|d ��q�z| j||||d�} W�n*�t�yb���| j�rZ|������|�Y�S�0�| |d<�||d<�t�d||��|����|�j ||fi�|��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. )rC���r���FZassert_same_host�redirectr���i/��ZGET�retries)rZ���N)�responseZ_poolzRedirecting %s -> %s)r���rY���r���rK���r���rC���r���r���rX����urlopenZrequest_uriZget_redirect_locationr����statusr"���� isinstancer���Zfrom_intZremove_headers_on_redirectZis_same_hostr$���r ���Ziterkeysr���r&���Z incrementr ���Zraise_on_redirectZ drain_conn�log�info)r<����methodrP���rZ���rE���rQ���Zconnr\���Zredirect_locationr[���r����headerr+���r+���r,���r]���`��sL���� � zPoolManager.urlopen)r1���N)N)Nr/���N)N)N)T)�__name__� __module__�__qualname__�__doc__rV���rW���r7���r?���rB���rF���r@���rK���rI���rM���rR���rH���rX���rY���r]���r+���r+���r+���r,���r�������s ��� r���c�����������������������sH���e�Zd�ZdZd��fdd� Zd��fdd � Zdd d�Zd��fd d� Z���ZS�)r���a>�� 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. Example: >>> proxy = urllib3.ProxyManager('http://localhost:3128/') >>> r1 = proxy.request('GET', 'http://google.com/') >>> r2 = proxy.request('GET', 'http://httpbin.org/') >>> len(proxy.pools) 1 >>> r3 = proxy.request('GET', 'https://httpbin.org/') >>> r4 = proxy.request('GET', 'https://twitter.com/') >>> len(proxy.pools) 3 r1���NFc����������� ���������s����t�|t�rd|j|j|jf�}t|�}|jdvr:t|j��|jsZt�|jd�} |j | d�}||�_ |pfi�|�_||�_t ||�|�_|�j |d<�|�j|d<�|�j|d<�tt|��j||fi�|���d�S�)Nz %s://%s:%ir.���rG���)rC����_proxyr���Z _proxy_config)r_���r���r���r���rC���r���r ���r���r"����_replacerV���� proxy_headers�proxy_ssl_contextr���rW����superr���r7���) r<���� proxy_urlr=���r���rj���rk���r���r8���rV���rC����� __class__r+���r,���r7������s(���� � zProxyManager.__init__r/���c��������������������sD���|dkr t�t|��j||||d�S�t�t|��j|�jj|�jj|�jj|d�S�)Nr0���)rJ���)rl���r���rK���rV���r���rC���r���)r<���r���rC���r���rJ���rn���r+���r,���rK������s���� � �z!ProxyManager.connection_from_hostc�����������������C���s0���ddi}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. ZAcceptz*/*ZHost)r����netloc�update)r<���rP���r���Zheaders_rp���r+���r+���r,����_set_proxy_headers���s���� zProxyManager._set_proxy_headersTc��������������������sV���t�|�}t|�j|�j|j�s8|�d|�j�}|��||�|d<�tt |��j ||fd|i|��S�)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.r���rZ���)r���r���rV���rW���r���r"���r���rr���rl���r���r]���)r<���rb���rP���rZ���rE���rQ���r���rn���r+���r,���r]��� ��s ����zProxyManager.urlopen)r1���NNNF)Nr/���N)N)T) rd���re���rf���rg���r7���rK���rr���r]���� __classcell__r+���r+���rn���r,���r������s���*������% r���c�����������������K���s���t�f�d|�i|��S�)Nrm���)r���)rP���rE���r+���r+���r,���r�����s����r���).Z __future__r����collections� functoolsZlogging�_collectionsr���Zconnectionpoolr���r���r���� exceptionsr���r ���r ���r���r���Zpackagesr ���Zpackages.six.moves.urllib.parser���Zrequestr���Z util.proxyr���Z util.retryr���Zutil.urlr����__all__Z getLoggerrd���r`���rD���Z_key_fields� namedtupler���Z_proxy_config_fieldsr���r-����partialr;���r:���r���r���r���r+���r+���r+���r,����<module>���s:��� 6 � ��s