Files
intellecton/venv/lib/python3.12/site-packages/urllib3/__pycache__/poolmanager.cpython-312.pyc
T

258 lines
24 KiB
Plaintext
Raw Normal View History

Ë
jW]ãóddlmZddlZddlZddlZddlZddlmZddlm Z ddl
m Z m Z ddl
mZddlmZdd lmZmZmZdd
lmZmZmZmZdd lmZdd lmZdd
lmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ejNr
ddl(Z(ddl)m*Z*gd¢Z+ejXe-«Z.dZ/dZ0Gddejb«Z2 ddZ3ejhe3e2«ejhe3e2«dœZ5eedœZ6Gdde«Z7Gdde7«Z8ddZ9y) é)Ú 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ó4eZdZUdZded<ded<ded<ded<d ed
<d ed <d
ed<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<d ed!<d"ed#<d ed$<d%ed&<d'ed(<d ed)<d*ed+<ded,<ded-<ded.<y/)0Ú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_hostú
int | NoneÚkey_portzTimeout | float | int | NoneÚ key_timeoutzRetry | bool | int | NoneÚ key_retriesz bool | NoneÚ key_blockztuple[str, int] | NoneÚkey_source_addressú
str | 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ú
Url | NoneÚ
key__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_blocksizeN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú__annotations__©óúV/home/antigravity/intellecton/venv/lib/python3.12/site-packages/urllib3/poolmanager.pyr*r*8ñðƒO؃MØÓØÓØÓØ Ó ØÓØÓØÓØÓØÓØÓØÔrTr*có|j«}|dj«|d<|dj«|d<dD],}||vsŒ||Œt||j««||<Œ.|j d«}|t |«|d<t
|j««D]}|j|«|d|z<Œ|jD] }||vsŒd||<Œ|j d«€ t|d<|di|¤Ž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_rMrS) ÚcopyÚlowerÚ frozensetÚitemsÚgetÚtupleÚlistÚkeysÚpopÚ_fieldsÚ_DEFAULT_BLOCKSIZE)Ú key_classÚrequest_contextÚcontextÚkeyÚ socket_optsÚfields rUÚ_default_key_normalizerro_s'ð.×$€GØ Ñ1€GˆHÑØ˜f‘o×-€GˆF;ˆØ 'Š>˜g c™lÑ$ W¨S¡\×%7Ñ%7Ó%9Ó:ˆGCŠLð —+‘+Ð/€KØÐÜ$)¨+Ó$6ˆÐ ÑG—LL“NÓ1ˆØ '§ ¡ ¨CÓ 0ˆ˜ Òð×"ˆØ ˜Ò Ø!ˆGEŠNð
‡{{+Ü#5ˆÑ á Ñ  ÐrT©ÚhttpÚhttpscó.eZdZUdZdZded<dZded< d dˆfd
ZddZ dd „Z d dd
Z
dd Z d dd Z dd
Z
ddZ d ddZ ddZd dZ d! d"dZˆxZS)#raV
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
NrCÚproxyrFÚ proxy_configc ó$t||«d|vr?|d}t|t«s*tj|«}|j «}||d<||_|t|«|_t|_ tj «|_
y)retries) ÚsuperÚ__init__Ú
isinstancerÚfrom_intr^Úconnection_pool_kwrÚpoolsÚpool_classes_by_schemeÚkey_fn_by_scheme)ÚselfÚ num_poolsrYr|rwÚ __class__s €rUryzPoolManager.__init__Çsø€ô Ñ˜Ô Ð Ñ3ˆGܘg¤uÔŸ.™.¨Ó1Ø%7×%<Ñ%<Ó%>Ð"Ø07Ð" -Ø"4ˆÔá Ü*¨9ÓŒ
ô'=ˆÔ#Ü 0× 5Ñ 5Ó 7ˆÕrTcó|S©NrS©r€s rUÚ __enter__zPoolManager.__enter__æs؈ rTcó$|j«y)NF)Úclear)r€Úexc_typeÚexc_valÚexc_tbs rUÚ__exit__zPoolManager.__exit__ésð
Œ àrTcó|j|}||jj«}|jd«€ t|d<dD]}|j |d«Œ|dk(rt D]}|j |d«Œ|||fi|¤ŽS)
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)rWrXÚportrq)r~r|r^rbrhrfÚ SSL_KEYWORDS)r€rWrXrrjÚpool_clsrlÚkws rUÚ _new_poolzPoolManager._new_poolóð .2×-HÑ-HÈÑ-PˆØ Ð "×5×<ˆ × Ñ ˜ 3Ü+=ˆO˜KÑ  +ˆCØ × Ñ   TÕ   Ü
.Ø×# B¨Õ
˜˜6 6rTcó8|jj«y)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)r}rˆr…s rUrˆzPoolManager.clearsð
×ÑÕrTcóØ|s td«|j|«}|xsd|d<|s'tj|dj «d«}||d<||d<|j |«S)
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.rqrWéPrrX)rÚ_merge_pool_kwargsr
rbr_Úconnection_from_context)r€rXrrWÚ pool_kwargsrjs rUÚconnection_from_hostz PoolManager.connection_from_host"szñ"Ü$Ð%9Ó ×1°+ÓØ$*Ò$4¨fˆ˜ÑÜ!×% o°hÑ&?×&EÑ&EÓ&GÈÓLˆDØ"&ˆ˜ÑØ"&ˆ˜Ñà×+¨OÓ<rTcó d|vr+tjdt«|jd«|dj «}|j
j
|«}|s t|«||«}|j||¬«S)
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.
ÚstrictzbThe 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v3.0.rW©rj) ÚwarningsÚwarnÚ
FutureWarningrfr_rrbrÚconnection_from_pool_key)r€rjrWÚpool_key_constructorÚpool_keys rUr˜z#PoolManager.connection_from_context?sˆð Ñ M‰Mðô
ð
× Ñ  Ô   ÑØ8¸ÓÙ"  Óà×,¨XÀÐWrTcó|jj5|jj|«}|r |cddd«S|d}|d}|d}|j||||¬«}||j|<ddd«|S#1swYSxYw)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.
NrWrXrr)r}Úlockrbr“)r€rjÚpoolrWrXrs rUz$PoolManager.connection_from_pool_keyXs•ðZ‰Z_‰_ñ —::—>> +ˆØ÷ % .ˆ" *ˆ" *ˆ—>> &¨$°ÀoVˆDØ#'ˆDJ‰J ÷ ˆ ÷ ˆ úsA=Á3A=Á=Bcó~t|«}|j|j|j|j|¬«S)
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.
)rrWr™)rrXrrW)r€Úurlr™Úus rUÚconnection_from_urlzPoolManager.connection_from_urlrs:ô
cNˆØ×
F‰F˜Ÿ¨¯©¸kð
ð
rTcó¤|jj«}|r$|j«D]\}}| ||=Œ
|||<Œ|S#t$rYŒ!wxYw)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.
)r|r^raÚKeyError)r€ÚoverrideÚbase_pool_kwargsrlÚvalues rUr—zPoolManager._merge_pool_kwargs„sqð ×Ù Ø&Ÿn™nÓ
2
Ø,¨SÑ-2Ð$ 
 Ðøô ÙðúsAÁ AÁAcót|jyt|j|j|j« S)
Indicates if the proxy requires the complete destination URL in the
request. Normally this is only needed when not using an HTTP CONNECT
tunnel.
F)rtrrurW)r€Ú
parsed_urls rUÚ!_proxy_requires_url_absolute_formz-PoolManager._proxy_requires_url_absolute_formšs:ð :‰:Ð Øä J‰J˜×)¨:×+<Ñ+<ó
ð
ð
rTc ó´t|«}|jtjdtd¬«|j |j |j|j¬«}d|d<d|d<d |vr|j|d <|j|«r|j||fi|¤Ž}n|j||jfi|¤Ž}|xr|j«}|s|St||«}|jd
k(r&d }d|d <t|d «j!«|d <|j#d
|j$«} t'| t(«st)j*| |¬«} | j,rb|j/|«sQ|d j1«}
|d D]1} | j3«| j,vsŒ |
j5| d«Œ3|
|d < | j7||||¬«} | |d
<||d<t>jAd||«|j=«|j||fi|¤ŽS#t8$r"| j:r|j=«|cYSwxYw)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.
Nzõ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Ú
stacklevel)rrWassert_same_hostÚredirectrYi/ÚGETÚbodyrw)r¸)ÚresponseÚ_poolzRedirecting %s -> %s)!rrWr rXrrYÚurlopenÚ request_uriÚget_redirect_locationrÚstatusrÚ_prepare_for_method_changerbrwrzrr{Úremove_headers_on_redirectÚ is_same_hostr^r_rfÚ incrementrÚraise_on_redirectÚ
drain_connÚlogÚinfo) r€Úmethodr¨r¸rÚconnr»Úredirect_locationrwÚ new_headersÚheaders rUzPoolManager.urlopen§sVô
c‹Nˆà 8‰8Ð Ü M‰MðAôõ

ðׯ©°a·f±fÀQÇXÁXÐà!&ˆÐ ÑØˆˆ:‰à ˜BÑ Ø ŸL™LˆBˆy‰Mà × 1°!Ô #t—|| F¨CÑ6°2Ñ6‰Hà#t—|| F¨A¯M©MÑ@¸@ˆ×)GÑ)GÓ)IÐ٠؈Oô$ CÐ):Óà ?‰?˜cÒ ˆFàˆBˆv‰JÜ*¨2¨i©=ÓVˆBˆy‰Mà—&&˜ H×$4Ñ$4Ó5ˆÜ˜'¤5Ô—nn W°xÔ@ˆ
× -°d×6GÑ6GØ ô7
ð˜Y™-×.ˆKؘY™-ò
2Ø—<<“> W×%GÑ%GÒ—OO F¨DÕ
(ˆBˆy‰Mð Ø×°¸hÈdÐSˆ ˆˆ9‰
؈:‰ä ÐÐ.?Ô×ÑÔØˆt|‰|˜FÐ$5Ñ<¸Ñ<øôò Ø×רŠOð  úsÇH,È,(IÉI)é
N)rÚintrYútyping.Mapping[str, str] | Noner|ú
typing.AnyÚreturnÚNone)r)r‰ztype[BaseException] | NonerŠzBaseException | NonerzTracebackType | NonerÒztyping.Literal[False]r„)
rWr+rXr+rrjúdict[str, typing.Any] | NonerÒr )©Nrq
rXr4rr.rWr4r™r )rjúdict[str, typing.Any]rÒr )r*rjr×r )r+r™r )r­r×)rÚbool©
r+r+r¸rr)rNrOrPrQrtrRruryr†r“rˆr—Ú
__classcell__©rs@rUrr¢ø…ñðB€Eˆ:ÓØ'+€LÐØ37ðð
õ 8ó>ðàððð
ó ð9=ð $ð$ð$ð $
 $
ó
$7óLð Ø#Ø48ð ððð 
 
ó
=ð:XØXà óXð2ØðØ2Gðà óð6EIð
Øð
Ø%Að
à ó
ð$ Ø à ó ó, 
ð7;ðPðP=Ø #ðP=Ø/3ðP=ØBLðP÷P=rTrcó¸eZdZdZ d dˆfd
Z d d ˆfd
Z d
d dZ d d
ˆfd
ZˆxZS)r
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", "http://google.com/")
resp2 = proxy.request("GET", "http://httpbin.org/")
# One pool was shared by both plain HTTP requests.
print(len(proxy.pools))
# 1
resp3 = proxy.request("GET", "https://httpbin.org/")