Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
poolmanager.cpython-313.pyc265 linesDownload Raw Back to __pycache__
1�

2��jW]�� �SSKJr SSKrSSKrSSKrSSKrSSKJr SSKJ	r	 SSK3JrJr SSK
Jr SSKJr SS	KJrJrJr SS4KJrJrJrJr SSKJr SSKJr SS
KJr SSK J!r! SSK"J#r# SSK$J%r%J&r& \RN(a5SSK(r(SSK)J*r* /SQr+\RX"\-5r.Sr/Sr0"SS\Rb5r2SSjr3\Rh"\3\25\Rh"\3\25S.r5\\S.r6"SS\5r7"SS\75r8SSjr9g) �)�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)�Self)�PoolManager�ProxyManager�proxy_from_url)�key_file�	cert_file�	cert_reqs�ca_certs�ca_cert_data�ssl_version�ssl_minimum_version�ssl_maximum_version�ca_cert_dir�ssl_context�key_password�server_hostnamei@c�<�\rSrSr%SrS\S'S\S'S\S'S\S	'S6\S'S\S
'S\S'S\S'S\S'S\S'S\S'S\S'S\S'S\S'S\S'S\S'S\S'S\S'S\S 'S!\S"'S#\S$'S!\S%'S&\S''S(\S)'S!\S*'S+\S,'S\S-'S\S.'S\S/'S0rg1)2�PoolKey�8z�7All known keyword arguments that could be provided to the pool manager, its8pools, or the underlying connections.9 10All custom key schemes should include the fields in this key at a minimum.11�str�12key_scheme�key_host�13int | None�key_portzTimeout | float | int | None�key_timeoutzRetry | bool | int | None�key_retrieszbool | None�	key_blockztuple[str, int] | None�key_source_address�14str | None�key_key_file�key_key_password�
key_cert_file�
key_cert_reqs�key_ca_certszstr | bytes | None�key_ca_cert_datazint | str | None�key_ssl_versionzssl.TLSVersion | None�key_ssl_minimum_version�key_ssl_maximum_version�key_ca_cert_dir�ssl.SSLContext | None�key_ssl_context�key_maxsizez!frozenset[tuple[str, str]] | None�key_headers�15Url | None�16key__proxy�key__proxy_headers�ProxyConfig | 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_blocksize�N)�__name__�17__module__�__qualname__�__firstlineno__�__doc__�__annotations__�__static_attributes__rO��YD:\code\apps\devtools\python\user_packages\Python313\site-packages\urllib3/poolmanager.pyr*r*8s�����O��M���-�-�*�*���.�.��� � �������(�(�%�%�2�2�2�2���*�*���2�2���9�9�)�)�3�3�9�9�*�*�&�&�#�#��rWr*c��UR5nUSR5US'USR5US'SH.nX2;dM18X#cM[X#R55X#'M0 UR	S5nUb[U5US'[
UR55HnURU5USU-'M URHnXR;dM19SX%'M UR	S5c	[US'U"S0UD6$)	a�20Create a pool key out of a request context dictionary.21 22According to RFC 3986, both the scheme and host are case-insensitive.23Therefore, this function normalizes both before constructing the pool24key for an HTTPS request. If you wish to change this behaviour, provide25alternate callables to ``key_fn_by_scheme``.26 27:param key_class:28    The class to use when constructing the key. This should be a namedtuple29    with the ``scheme`` and ``host`` keys at a minimum.30:type  key_class: namedtuple31:param request_context:32    A dictionary-like object that contain the context for a request.33:type  request_context: dict34 35:return: A namedtuple that can be used as a connection pool key.36:rtype:  PoolKey37�scheme�host)�headers�_proxy_headers�_socks_optionsN�socket_options�key_rNrO)�copy�lower�	frozenset�items�get�tuple�list�keys�pop�_fields�_DEFAULT_BLOCKSIZE)�	key_class�request_context�context�key�socket_opts�fields      rX�_default_key_normalizerrr_s��.�"�"�$�G���)�/�/�1�G�H���f�o�+�+�-�G�F�O�?���>�g�l�6�$�W�\�%7�%7�%9�:�G�L�?��+�+�.�/�K���$)�+�$6�� �!��G�L�L�N�#�� '���C� 0������$��"�"����!�G�N�#�38�{�{�?�#�+�#5��� ���w��rW��http�httpsc�Z^�\rSrSr%SrSrS\S'SrS\S'SSU4SjjjrSS	jr	SS39jr40SSSjjrSSjrSSS
jjr
SSjrSSjrSS SjjrS!SjrS"SjrS#S$SjjrSrU=r$)%r�a41Allows for arbitrary requests while transparently keeping track of42necessary connection pools for you.43 44:param num_pools:45    Number of connection pools to cache before discarding the least46    recently used pool.47 48:param headers:49    Headers to include with all requests, unless other headers are given50    explicitly.51 52:param \**connection_pool_kw:53    Additional parameters are used to create fresh54    :class:`urllib3.connectionpool.ConnectionPool` instances.55 56Example:57 58.. code-block:: python59 60    import urllib361 62    http = urllib3.PoolManager(num_pools=2)63 64    resp1 = http.request("GET", "https://google.com/")65    resp2 = http.request("GET", "https://google.com/mail")66    resp3 = http.request("GET", "https://yahoo.com/")67 68    print(len(http.pools))69    # 270 71NrD�proxyrG�proxy_configc�0>�[TU]U5 SU;aDUSn[U[5(d*[R"U5nUR5nXCS'X0lU [U5Ul[Ul	[R5Ul72g)N�retries)�super�__init__�73isinstancer�from_intra�connection_pool_kwr�pools�pool_classes_by_scheme�key_fn_by_scheme)�self�	num_poolsr\r�r{�	__class__s     �rXr}�PoolManager.__init__�s����	����!��*�*�(��3�G��g�u�-�-��.�.��1��%7�%<�%<�%>�"�07�9�-�"4���*�9�5��74�'=��#� 0� 5� 5� 7��rWc��U$�NrO�r�s rX�	__enter__�PoolManager.__enter__�s���rWc�$�UR5 g)NF)�clear)r��exc_type�exc_val�exc_tbs    rX�__exit__�PoolManager.__exit__�s��	
�75�76��rWc�"�URUnUcURR5nURS5c	[US'SHnURUS5 M US:Xa[HnURUS5 M U"X#40UD6$)a�77Create a new :class:`urllib3.connectionpool.ConnectionPool` based on host, port, scheme, and78any additional pool keyword arguments.79 80If ``request_context`` is provided, it is provided as keyword arguments81to the pool class used. This method is used to actually create the82connection pools handed out by :meth:`connection_from_url` and83companion methods. It is intended to be overridden for customization.84N�	blocksize)rZr[�portrt)r�r�rarerkri�SSL_KEYWORDS)r�rZr[r�rm�pool_clsro�kws        rX�	_new_pool�PoolManager._new_pool�s��� .2�-H�-H��-P���"�"�5�5�:�:�<�O����{�+�3�+=�O�K�(�.�C�����T�*�.��V��"���#�#�B��-�#���6�o�6�6rWc�8�URR5 g)z�85Empty our store of pools and direct them all to close.86 87This will not affect in-flight connections, but they will not be88re-used after completion.89N)r�r�r�s rXr��PoolManager.clears��	
�90�91���rWc���U(d[S5eURU5nU=(d SUS'U(d([R"USR	5S5nX%S'XS'URU5$)al92Get a :class:`urllib3.connectionpool.ConnectionPool` based on the host, port, and scheme.93 94If ``port`` isn't given, it will be derived from the ``scheme`` using95``urllib3.connectionpool.port_by_scheme``. If ``pool_kwargs`` is96provided, it is merged with the instance's ``connection_pool_kw``97variable and used to create the new connection pool, if one is98needed.99zNo host specified.rtrZ�Pr�r[)r�_merge_pool_kwargsr
rerb�connection_from_context)r�r[r�rZ�pool_kwargsrms      rX�connection_from_host� PoolManager.connection_from_host"sv��"�$�%9�:�:��1�1�+�>��$*�$4�f���!��!�%�%�o�h�&?�&E�&E�&G��L�D�"&���"&����+�+�O�<�<rWc��SU;a,[R"S[5 URS5 USR	5nUR100R
U5nU(d[U5eU"U5nURXAS9$)z�101Get a :class:`urllib3.connectionpool.ConnectionPool` based on the request context.102 103``request_context`` must at least contain the ``scheme`` key and its104value must be a key in ``key_fn_by_scheme`` instance variable.105�strictzbThe 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v3.0.rZ�rm)	�warnings�warn�
FutureWarningrirbr�rer�connection_from_pool_key)r�rmrZ�pool_key_constructor�pool_keys     rXr��#PoolManager.connection_from_context?s�����&��M�M�<��
�106
����)� ��*�0�0�2��#�4�4�8�8��@��#�"�6�*�*�'��8���,�,�X�,�W�WrWc��URR URRU5nU(aUsSSS5 $USnUSnUSnURXEXbS9nX0RU'SSS5 U$!,(df   W$=f)z�107Get a :class:`urllib3.connectionpool.ConnectionPool` based on the provided pool key.108 109``pool_key`` should be a namedtuple that only contains immutable110objects. At a minimum it must have the ``scheme``, ``host``, and111``port`` fields.112NrZr[r�r�)r��lockrer�)r�r�rm�poolrZr[r�s       rXr��$PoolManager.connection_from_pool_keyXs����Z�Z�_�_��:�:�>�>�(�+�D����_�%�X�.�F�"�6�*�D�"�6�*�D��>�>�&��>�V�D�#'�J�J�x� �����_���s�$A<�-A<�<113Bc�x�[U5nURURURURUS9$)a�114Similar to :func:`urllib3.connectionpool.connection_from_url`.115 116If ``pool_kwargs`` is not provided and a new pool needs to be117constructed, ``self.connection_pool_kw`` is used to initialize118the :class:`urllib3.connectionpool.ConnectionPool`. If ``pool_kwargs``119is provided, it is used instead. Note that if a new pool does not120need to be created for the request, the provided ``pool_kwargs`` are121not used.122)r�rZr�)rr�r[r�rZ)r��urlr��us    rX�connection_from_url�PoolManager.connection_from_urlrs:��
�c�N���(�(�
�F�F�������k�)�123�	124rWc��URR5nU(a%UR5Hup4UcX#	M
XBU'M U$![a M$f=f)z�125Merge a dictionary of override values for self.connection_pool_kw.126 127This does not modify self.connection_pool_kw and returns a new dict.128Any keys in the override dictionary with a value of ``None`` are129removed from the merged dictionary.130)r�rard�KeyError)r��override�base_pool_kwargsro�values     rXr��PoolManager._merge_pool_kwargs�se�� �2�2�7�7�9���&�n�n�.�131���=��,�1�-2�S�)�/� ���	$����s�A	�	132A�Ac�~�URcg[URURUR5(+$)z�133Indicates if the proxy requires the complete destination URL in the134request.  Normally this is only needed when not using an HTTP CONNECT135tunnel.136F)rxrryrZ)r��137parsed_urls  rX�!_proxy_requires_url_absolute_form�-PoolManager._proxy_requires_url_absolute_form�s:���:�:���2��J�J��)�)�:�+<�+<�138�139�	140rWc���[U5nURc[R"S[SS9 URURURURS9nSUS'SUS'S	U;aURUS	'URU5(aUR"X40UD6nOUR"XR40UD6nU=(a UR5nU(dU$[X(5nURS141:Xa&SnSUS'[US	5R!5US	'UR#S
UR$5n	['U	[(5(d[(R*"X�S9n	U	R,(akUR/U5(dUUS	R15n142US	H5nUR35U	R,;dM#U143R5US5 M7 X�S	'U	R7XXvS9n	X�S
'X4S'[>RASX(5 UR=5 UR"X40UD6$![8a' U	R:(aUR=5 eUs$f=f)a144Same as :meth:`urllib3.HTTPConnectionPool.urlopen`145with custom cross-host redirect logic and only sends the request-uri146portion of the ``url``.147 148The given ``url`` parameter must be absolute, such that an appropriate149:class:`urllib3.connectionpool.ConnectionPool` can be chosen for it.150Nz�URLs without a scheme (ie 'https://') are deprecated and will raise an error in urllib3 v3.0. To avoid this FutureWarning ensure all URLs start with 'https://' or 'http://'. Read more in this issue: https://github.com/urllib3/urllib3/issues/2920�)�category�151stacklevel)r�rZF�assert_same_host�redirectr\i/�GET�bodyr{)r�)�response�_poolzRedirecting %s -> %s)!rrZr�r�r�r�r[r�r\r��urlopen�request_uri�get_redirect_locationr�statusr�_prepare_for_method_changerer{r~rr�remove_headers_on_redirect�is_same_hostrarbri�	incrementr�raise_on_redirect�152drain_conn�log�info)r��methodr�r�r�r��connr��redirect_locationr{�new_headers�headers            rXr��PoolManager.urlopen�s=��
�c�N���8�8���M�M�A�'��

��(�(����a�f�f�Q�X�X�(�N��!&������:���B�� �L�L�B�y�M��1�1�!�4�4��|�|�F�6�2�6�H��|�|�F�M�M�@�R�@�H�$�I��)G�)G�)I�� ��O�$�C�;���?�?�c�!��F��B�v�J�*�2�i�=�9�T�T�V�B�y�M��&�&��H�$4�$4�5���'�5�)�)��n�n�W�@�G�153�-�-�d�6G�6G��7154�7155��Y�-�,�,�.�K��Y�-���<�<�>�W�%G�%G�G��O�O�F�D�1�(�(�y�M�	��'�'��h�'�S�G� �9�
�!�:�����'��@������|�|�F�<��<�<���	��(�(��#�#�%���O�		�s�-H>�>.I/�.I/)r�r�r�r�)�156N)r��intr\�typing.Mapping[str, str] | Noner��157typing.Any�return�None)r�r)r�ztype[BaseException] | Noner�zBaseException | Noner�zTracebackType | Noner�ztyping.Literal[False]r�)158rZr,r[r,r�r�rm�dict[str, typing.Any] | Noner�r)r�r��NrtN�159r[r5r�r/rZr5r�r�r�r)rm�dict[str, typing.Any]r�r)r�r*rmr�r�r)r�r,r�r�r�r)r�r�r�r�)r�rr��bool�T�160r�r,r�r,r�r�r�r�r�r)rPrQrRrSrTrxrUryr}r�r�r�r�r�r�r�r�r�r�r�rV�
__classcell__�r�s@rXrr�s�����B�E�:��'+�L�$�+��37�8��8�1�8�)�	8�161162�8�8�>��,��&��%�	�163164��9=�$7��$7��$7��	$7�1656�$7�166�
$7�L� �#�48�=��=��=��	=�1672�=�168�
=�:X�4�X�	�X�2���2G��	��6EI�169��170�%A�171�	�172�$ �4� �	� �,173�7;�P=��P=� #�P=�/3�P=�BL�P=�	�P=�P=rWrc��^�\rSrSrSrSS	U4SjjjrS174SU4SjjjrSS
SjjrSSU4SjjjrSr	U=r175$)ri�a176Behaves just like :class:`PoolManager`, but sends all requests through177the defined proxy, using the CONNECT method for HTTPS URLs.178 179:param proxy_url:180    The URL of the proxy to be used.181 182:param proxy_headers:183    A dictionary containing headers that will be sent to the proxy. In case184    of HTTP they are being sent with each request, while in the185    HTTPS/CONNECT case they are sent only once. Could be used for proxy186    authentication.187 188:param proxy_ssl_context:189    The proxy SSL context is used to establish the TLS connection to the190    proxy when using HTTPS proxies.191 192:param use_forwarding_for_https:193    (Defaults to False) If set to True will forward requests to the HTTPS194    proxy to be made on behalf of the client instead of creating a TLS195    tunnel via the CONNECT method. **Enabling this flag means that request196    and response headers and content will be visible from the HTTPS proxy**197    whereas tunneling keeps request and response headers and content198    private.  IP address, target hostname, SNI, and port are always visible199    to an HTTPS proxy even when this flag is disabled.200 201:param proxy_assert_hostname:202    The hostname of the certificate to verify against.203 204:param proxy_assert_fingerprint:205    The fingerprint of the certificate to verify against.206 207Example:208 209.. code-block:: python210 211    import urllib3212 213    proxy = urllib3.ProxyManager("https://localhost:3128/")214 215    resp1 = proxy.request("GET", "http://google.com/")216    resp2 = proxy.request("GET", "http://httpbin.org/")217 218    # One pool was shared by both plain HTTP requests.219    print(len(proxy.pools))220    # 1221 222    resp3 = proxy.request("GET", "https://httpbin.org/")223    resp4 = proxy.request("GET", "https://twitter.com/")224 225    # A separate pool was added for each HTTPS target.226    print(len(proxy.pools))227    # 3228 229c	�B>�[U[5(a)URSURSUR3n230OUn231[U2325nURS;a[
UR5eUR(d0[R"URS5nURUS9nX�l233U=(d 0UlXPl[UUUU5UlURU	S'URU	S'URU	S'[T
U]@"X#40U	D6 g)	Nz://�:rsr�)r��_proxyr]�
_proxy_config)r~rrZr[r�rrr
re�_replacerx�
proxy_headers�proxy_ssl_contextr234ryr|r})r��	proxy_urlr�r\r�r��use_forwarding_for_https�proxy_assert_hostname�proxy_assert_fingerprintr��
str_proxy_urlrxr�r�s             �rXr}�ProxyManager.__init__3s235����i�!3�4�4�(�/�/�0��I�N�N�3C�1�Y�^�^�DT�U�M�%�M��-�(���<�<�0�0�$�U�\�\�2�2��z�z�!�%�%�e�l�l�B�7�D��N�N��N�-�E��236�*�0�b���!2��'��$�!�$�	237���(,�z�z��8�$�/3�/A�/A��+�,�.2�.?�.?��?�+�
����B�/A�BrWc��>�US:Xa[TU]XX4S9$[TU]URRURRURR238US9$)Nru)r�)r|r�rxr[r�rZ)r�r[r�rZr�r�s     �rXr��!ProxyManager.connection_from_host\se����W���7�/��F�0��
��w�+��J�J�O�O�T�Z�Z�_�_�d�j�j�.?�.?�[�,�239�	240rWc�~�SS0n[U5RnU(aXCS'U(aURU5 U$)zx241Sets headers needed by proxies: specifically, the Accept and Host242headers. Only sets headers not provided by the user.243�Acceptz*/*�Host)r�netloc�update)r�r�r\�headers_rs     rX�_set_proxy_headers�ProxyManager._set_proxy_headersls<���e�$���3��&�&���%�V����O�O�G�$��rWc�>�[U5n[URURUR5(d0URSUR5nURX&5US'[TU]$"X4SU0UD6$)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.r\r�)244rrrxryrZrer\rr|r�)r�r�r�r�r�r�r\r�s       �rXr��ProxyManager.urlopen}sn���
�c�N��.�t�z�z�4�;L�;L�a�h�h�W�W��f�f�Y����5�G� �3�3�C�A�B�y�M��w��v�D�X�D��D�DrW)rxryr�r�)r�NNNFNN)r�r,r�r�r\r�r�r�r�r@r�r�r�z"None | str | typing.Literal[False]r�r5r�r�r�r�r�r�r�)r�r,r\r�r�ztyping.Mapping[str, str]r�r�)rPrQrRrSrTr}r�rr�rVr�r�s@rXrr�sA���6�v�37�9=�37�).�DH�/3�'C��'C��'C�1�	'C�2457�'C�1�
'C�#'�'C� B�'C�#-�'C�)�'C�246�'C�'C�X �#�48�247��248��249��	250�2512�252�253�
254�255�"DH����!@��	!��$7;�E��E� #�E�/3�E�BL�E�	�E�ErWrc��[SSU0UD6$)Nr�rO)r)r�r�s  rXrr�s���,�#�,��,�,rW)rlz
type[PoolKey]rmr�r�r*)r�r,r�r�r�r):�256__future__r�	functools�logging�typingr��typesr�urllib.parser�_collectionsrr�_request_methodsr	�257connectionr258�connectionpoolrrr
�259exceptionsrrrrr�r�util.connectionr�260util.proxyr�261util.retryr�util.timeoutr�util.urlrr�
TYPE_CHECKING�ssl�typing_extensionsr�__all__�	getLoggerrPr�r�rk�262NamedTupler*rr�partialr�r�rrrrOrWrX�<module>rs��"���
��� �?�,�#�S�S���'�1�7��!�$�	����&�263;������!��
�� ��$�f���$�N4 ��4 �/D�4 ��4 �x
���5�w�?�
�
�
�6��
@���264#5�?R�S��U=�.�U=�p265OE�;�OE�d-rW
codekingpro/portable-devtools · Team Ai