K i:]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*gdZ+ejXe-Z.dZ/dZ0GddejbZ2 ddZ3ejhe3e2ejhe3e2dZ5eedZ6GddeZ7Gdde7Z8ddZ9y) ) annotationsN) TracebackType)urljoin)HTTPHeaderDictRecentlyUsedContainer)RequestMethods) ProxyConfig)HTTPConnectionPoolHTTPSConnectionPoolport_by_scheme)LocationValueError MaxRetryErrorProxySchemeUnknownURLSchemeUnknown)BaseHTTPResponse)_TYPE_SOCKET_OPTIONS)connection_requires_http_tunnel)Retry)Timeout)Url parse_url)Self) PoolManager ProxyManagerproxy_from_url) key_file cert_file cert_reqsca_certs ca_cert_data ssl_versionssl_minimum_versionssl_maximum_version ca_cert_dir ssl_context key_passwordserver_hostnamei@c4eZdZUdZded<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/)0PoolKeyz 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_schemekey_host int | Nonekey_portzTimeout | float | int | None key_timeoutzRetry | bool | int | None key_retriesz bool | None key_blockztuple[str, int] | Nonekey_source_address str | None key_key_filekey_key_password key_cert_file key_cert_reqs key_ca_certszstr | bytes | Nonekey_ca_cert_datazint | str | Nonekey_ssl_versionzssl.TLSVersion | Nonekey_ssl_minimum_versionkey_ssl_maximum_versionkey_ca_cert_dirssl.SSLContext | Nonekey_ssl_context key_maxsizez!frozenset[tuple[str, str]] | None key_headers Url | None key__proxykey__proxy_headersProxyConfig | Nonekey__proxy_configz_TYPE_SOCKET_OPTIONS | Nonekey_socket_optionskey__socks_optionszbool | str | Nonekey_assert_hostnamekey_assert_fingerprintkey_server_hostname key_blocksizeN)__name__ __module__ __qualname____doc____annotations__Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/urllib3/poolmanager.pyr*r*8sOM--**..  ((%%2222**2299))3399**&&##rTr*c|j}|dj|d<|dj|d<dD],}||vs||t||j||<.|j d}|t ||d<t |jD]}|j||d|z<|jD] }||vsd||<|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 schemehost)headers_proxy_headers_socks_optionsNsocket_optionskey_rMrS) copylower frozensetitemsgettuplelistkeyspop_fields_DEFAULT_BLOCKSIZE) key_classrequest_contextcontextkey socket_optsfields rU_default_key_normalizerro_s'.""$G)//1GHfo++-GFO?; '>gcl6$WS\%7%7%9:GCL; ++./K$)+$6 !GLLN#1 ' C 0 1"""  !GEN" {{?#+#5  w rThttphttpsc.eZdZUdZdZded<dZded< d dfd ZddZ dd Z d dd Z dd Z d dd Z dd Z ddZ d ddZ ddZd dZ d! d"dZxZS)#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 NrCproxyrF proxy_configc >t||d|vrL|d}t|ts7|du}tj|d}||_|j }||d<||_|t||_ t|_ tj |_ y)NretriesFredirect) super__init__ isinstancerfrom_intraise_on_redirectr^connection_pool_kwrpoolspool_classes_by_schemekey_fn_by_scheme)self num_poolsrYrrwr~ __class__s rUr{zPoolManager.__init__s ! * *(3Ggu-%,5$8!..5A,=)%7%<%<%>"07"9-"4 *95 '=# 0 5 5 7rTc|SNrSrs rU __enter__zPoolManager.__enter__s rTc$|jy)NF)clear)rexc_typeexc_valexc_tbs rU__exit__zPoolManager.__exit__s rTc|j|}||jj}|jd t|d<dD]}|j |d|dk(rt D]}|j |d|||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 blocksize)rWrXportrq)rrr^rbrhrf SSL_KEYWORDS)rrWrXrrjpool_clsrlkws rU _new_poolzPoolManager._new_pools .2-H-H-P  ""55::$*$4f!!%%oh&?&E&E&GLD"&"&++O<"     ) *002#4488@#"6* *'8,,X,WWrTc|jj5|jj|}|r |cdddS|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)rlockrbr)rrrjpoolrWrXrs rUrz$PoolManager.connection_from_pool_keyZsZZ__ (::>>(+D ( (%X.F"6*D"6*D>>&$o>VD#'DJJx  (  ( sA=3A==Bc~t|}|j|j|j|j|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. )rrWr)rrrXrrW)rurlrus rUconnection_from_urlzPoolManager.connection_from_urlts: cN(( FFk)  rTc|jj}|r$|jD]\}}| ||= |||<|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. )rr^raKeyError)roverridebase_pool_kwargsrlvalues rUrzPoolManager._merge_pool_kwargssq 22779 &nn. 2 U=,S1-2$S) 2  $sA AAct|jyt|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. F)rtrrurW)r parsed_urls rU!_proxy_requires_url_absolute_formz-PoolManager._proxy_requires_url_absolute_forms: :: 2 JJ)):+<+<   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| d3| |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. 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)rrWFassert_same_hostryrYi/GETbodyrwrx)response_poolzRedirecting %s -> %s)!rrWrrrrrXrrYrurlopen request_uriget_redirect_locationrstatusr_prepare_for_method_changerbrwr|rr}remove_headers_on_redirect is_same_hostr^r_rf incrementrr~ drain_connloginfo) rmethodrryrrconnrredirect_locationrw new_headersheaders rUrzPoolManager.urlopensV cN 88  MMA,  ((affQXX(N!& : B  LLByM  1 1! 4#t||FC626H#t||FAMM@R@H$I)G)G)I O$C):; ??c !FBvJ*2i=9TTVByM&&H$4$45'5)nnWx@G  - -d6G6G 7 Y-,,.KY- 2<<>W%G%GGOOFD1 2(ByM ''hd'SG 9 !: '.?@t||F$5<<< ((##%O  sH,,(II) N)rintrYtyping.Mapping[str, str] | Noner typing.AnyreturnNone)rr)rztype[BaseException] | NonerzBaseException | NonerzTracebackType | Nonerztyping.Literal[False]r) rWr+rXr+rrrjdict[str, typing.Any] | Nonerr )rrNrqN rXr4rr.rWr4rrrr )rjdict[str, typing.Any]rr )rr*rjrrr )rr+rrrr )rrrr)rrrboolT rr+rr+ryrrrrr)rNrOrPrQrtrRrur{rrrrrrrrrrr __classcell__rs@rUrrsBE:'+L$+378818) 8  8B,&%   9= $7$7$7 $7 6 $7  $7L #48 === = 2 =  =:X4X X22G 6EI  %A  $ 4  ,  7;P=P= #P=/3P=BLP= P=rTrceZdZdZ d dfd Z d d fd Z d d dZ d d fd ZxZS)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 c  (t|tr)|jd|jd|j} n|} t | } | jdvrt | j| js2tj| jd} | j| } | |_ |xsi|_ ||_ t|||||_|j| d<|j| d<|j| d<t |@||fi| y) Nz://:rpr)r_proxyrZ _proxy_config)r|r rWrXrrrr rb_replacert proxy_headersproxy_ssl_contextr rurzr{)r proxy_urlrrYrruse_forwarding_for_httpsproxy_assert_hostnameproxy_assert_fingerprintr str_proxy_urlrtrrs rUr{zProxyManager.__init__3s  i!3 4(//0INN3C1Y^^DTUM%M-( <<0 0$U\\2 2zz!%%ellB7DNNN-E *0b!2'  $ ! $  (,zz8$/3/A/A+,.2.?.??+ GB/ABrTc|dk(rt|||||St||jj|jj|jj |S)Nrr)r)rzrrtrXrrW)rrXrrWrrs rUrz!ProxyManager.connection_from_host\si W 7/dF 0 w+ JJOOTZZ__djj.?.?[,  rTclddi}t|j}|r||d<|r|j||S)z Sets headers needed by proxies: specifically, the Accept and Host headers. Only sets headers not provided by the user. Acceptz*/*Host)rnetlocupdate)rrrYheaders_rs rU_set_proxy_headerszProxyManager._set_proxy_headersls>e$3&& %HV   OOG $rTc t|}t|j|j|js1|j d|j }|j|||d<t|$||fd|i|S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rYry) rrrtrurWrbrYrrzr)rrrryrrrYrs rUrzProxyManager.urlopen}so cN.tzz4;L;LahhWffY 5G 33CAByMwvsDXDDDrT)rNNNFNN)rr+rrrYrrrrr?rrrz"None | str | typing.Literal[False]rr4rrrrrrr)rr+rYrrztyping.Mapping[str, str]rr) rNrOrPrQr{rrrrrs@rUrrs64r379=37).DH/3'C'C'C1 'C 7 'C 1 'C#''C B'C#-'C)'C 'CX #48      2    "DH!@ !$7; E E # E/3 EBL E  E ErTrc tdd|i|S)NrrS)r)rrs rUrrs  ,# , ,,rT)riz type[PoolKey]rjrrr*)rr+rrrr): __future__r functoolsloggingtypingrtypesr urllib.parser _collectionsrr_request_methodsr connectionr connectionpoolr r r exceptionsrrrrrrutil.connectionr util.proxyr util.retryr util.timeoutrutil.urlrr TYPE_CHECKINGssltyping_extensionsr__all__ getLoggerrNrrrh NamedTupler*ropartialrrrrrrSrTrUr s"  ?,#SS '17!$ & ;g!  $f$N4 4 /D4  4 x I  5w ? Y  6 @ #5?RSW=.W=t ME;ME`-rT