bgxXddlmZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZmZmZdd lmZmZmZmZdd lmZdd lmZdd lmZddlm Z ddl!m"Z"ddl#m$Z$m%Z%ej&r ddl'Z'ddl(m)Z)gdZ*ej+e,Z-dZ.dZ/ej0dZ1Gddej2Z3d(dZ4ej5e4e3ej5e4e3dZ6eedZ7Gdd e Z8Gd!d"e8Z9d)d'Z:dS)*) annotationsN) TracebackType)urljoin)RecentlyUsedContainer)RequestMethods) ProxyConfig)HTTPConnectionPoolHTTPSConnectionPoolport_by_scheme)LocationValueError MaxRetryErrorProxySchemeUnknownURLSchemeUnknown)BaseHTTPResponse)_TYPE_SOCKET_OPTIONS)connection_requires_http_tunnel)Retry)Timeout)Url parse_url)Literal) PoolManager ProxyManagerproxy_from_url) key_file cert_file cert_reqsca_certs ssl_versionssl_minimum_versionssl_maximum_version ca_cert_dir ssl_context key_passwordserver_hostnamei@_SelfTc,eZdZUdZded<ded<ded<ded<d ed <d ed <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_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_certszint | 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__J/opt/cloudlinux/venv/lib64/python3.11/site-packages/urllib3/poolmanager.pyr)r)9shOOOMMM----****....    %%%%22222222****22229999))))33339999****&&&&####rRr) key_class type[PoolKey]request_contextdict[str, typing.Any]returncX|}|d|d<|d|d<dD]8}||vr2||*t||||<9|d}|t ||d<t |D]}|||d|z<|j D] }||vrd||< |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_rKrQ) copylower frozensetitemsgettuplelistkeyspop_fields_DEFAULT_BLOCKSIZE)rTrVcontextkey socket_optsfields rS_default_key_normalizerrp_sV.""$$G)//11GHfo++--GFO?;; '>>gcl6$WS\%7%7%9%9::GCL++.//K$)+$6$6 !GLLNN##11 ' C 0 0 """   !GEN{{?##+#5 9  w  rRhttphttpsceZdZUdZdZded<dZded< d=d>fd Zd?dZd@dZ dAdBd#Z dCd$Z dDdEd)Z dFd+Z dGd.Z dAdHd0ZdId2ZdJd6Z dKdLd<ZxZS)MraV 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 NrAproxyrD proxy_config num_poolsintr\typing.Mapping[str, str] | Noneconnection_pool_kw typing.AnyrXNonec t|||_|t||_t |_t |_dSN)super__init__r{rpoolspool_classes_by_schemekey_fn_by_schemera)selfrxr\r{ __class__s rSrzPoolManager.__init__s^ !!!"4 F*955 '=# 0 5 5 7 7rRrr'c|SrrQrs rS __enter__zPoolManager.__enter__s rRexc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneLiteral[False]c.|dS)NF)clear)rrrrs rS__exit__zPoolManager.__exit__s urRrZr*r[portrVdict[str, typing.Any] | Noner c&|j|}||j}|d t|d<dD]}||d|dkr t D]}||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)rZr[rrr)rr{rarerkri SSL_KEYWORDS)rrZr[rrVpool_clsrmkws rS _new_poolzPoolManager._new_pools .2-H-P  ""5::<>$*$4f! M!%oh&?&E&E&G&GLLD"&"&++O<<"       ) ) ) *0022#488@@# +"6** *''88,,X,WWWrRrr)c|jj5|j|}|r|cdddS|d}|d}|d}|||||}||j|<dddn #1swxYwY|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. NrZr[rr)rlockrer)rrrVpoolrZr[rs rSrz$PoolManager.connection_from_pool_keyJsZ_ ( (:>>(++D  ( ( ( ( ( ( ( (%X.F"6*D"6*D>>&$o>VVD#'DJx  ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( sA?;A??BBurlcpt|}||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. )rrZr)rrr[rrZ)rrrus rSconnection_from_urlzPoolManager.connection_from_urlds; cNN(( Fk)   rRoverridec|j}|r6|D]!\}}| ||= #t$rYwxYw|||<"|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. )r{rardKeyError)rrbase_pool_kwargsrmvalues rSrzPoolManager._merge_pool_kwargsvs 27799  2&nn.. 2 2 U=,S11#-2$S))s< A A  parsed_urlrboolcV|jdSt|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)rurrvrZ)rrs rS!_proxy_requires_url_absolute_formz-PoolManager._proxy_requires_url_absolute_forms7 : 52 J):+<    rRTmethodredirectrrc Vt|}|jtjdtd||j|j|j}d|d<d|d<d |vr |j|d <| |r|j ||fi|}n|j ||j fi|}|o| }|s|St||}|jd krd }|d } t!| t"st#j| | } | jrp||s[|d } |d D]3} | | jvr| | d4| |d < | ||||} n.#t2$r!| jr||cYSwxYw| |d <||d<t8d||||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. 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)rrZFassert_same_hostrr\i/GETretries)r)response_poolzRedirecting %s -> %s)rrZrrrrr[rr\rurlopen request_uriget_redirect_locationrstatusre isinstancerfrom_intremove_headers_on_redirect is_same_hostrarbri incrementrraise_on_redirect drain_connloginfo) rrrrrrconnrredirect_locationr new_headersheaders rSrzPoolManager.urlopens cNN 8  MA,     ((afQX(NN!& : B   LByM  1 1! 4 4 A#t|FC66266HH#t|FAM@@R@@H$I)G)G)I)I  O$C):;; ?c ! !F&&##'5)) AnWx@@@G  - (d6G6G 7 7  (Y-,,..KY- 2 2<<>>W%GGGOOFD111'ByM ''hd'SSGG   ( ##%%%OOO    9 !: '.?@@@t|F$5<<<< 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 rwNF proxy_urlr*rxryr\rz proxy_headersproxy_ssl_contextr=use_forwarding_for_httpsrproxy_assert_hostnameNone | str | Literal[False]proxy_assert_fingerprintr3r{r|rXr}c  t|tr|jd|jd|j} n|} t | } | jdvrt | j| js0tj| jd} | | } | |_ |pi|_ ||_ t|||||_|j | d<|j | d<|j| d<tj||fi| dS) Nz://:rqr)r_proxyr] _proxy_config)rr rZr[rrrr re_replacerurrr rvrr)rrrxr\rrrrrr{ str_proxy_urlrurrs rSrzProxyManager.__init__ s+ i!3 4 4 &(/UUINUUY^UUMM%M-(( <0 0 0$U\22 2z .!%elB77DNNN--E *0b!2'  $ ! $   (,z8$/3/A+,.2.??+GBB/ABBBBBrRrrr[rr-rZrrr c|dkr%t||||St|jj|jj|jj|S)Nrs)r)rrrur[rrZ)rr[rrZrrs rSrz!ProxyManager.connection_from_hostIss W  77//dF 0 ww++ JOTZ_dj.?[,   rRrtyping.Mapping[str, str]crddi}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)rnetlocupdate)rrr\headers_rs rS_set_proxy_headerszProxyManager._set_proxy_headersYsMe$3&  &%HV   % OOG $ $ $rRTrrrrc t|}t|j|j|js4|d|j}||||d<tj ||fd|i|S)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.r\r) rrrurvrZrer\rrr)rrrrrrr\rs rSrzProxyManager.urlopenjs cNN.tz4;LahWW BffY 55G 33CAAByMuwwvsDDXDDDDrR)rwNNNFNN)rr*rxryr\rzrrzrr=rrrrrr3r{r|rXr}rrr)rr*r\rzrXrrr) rLrMrNrOrrrrrrs@rSrrs44r379=37).=A/3'C'C'C'C'C'C'CX #48        "DH$7; E E E E E E E E E E ErRrrr*rr|c tdd|i|S)NrrQ)r)rrs rSrrys  , ,# , , ,,rR)rTrUrVrWrXr))rr*rr|rXr); __future__r functoolsloggingtypingrtypesr urllib.parser _collectionsr_request_methodsr connectionr connectionpoolr r r exceptionsr rrrrrutil.connectionr util.proxyr util.retryr util.timeoutrutil.urlrr TYPE_CHECKINGssltyping_extensionsr__all__ getLoggerrLrrrkTypeVarr' NamedTupler)rppartialrrrrrrQrRrSrs""""""  //////,,,,,,######SSSSSSSSSS '&&&&&111111777777!!!!!!$$$$$$$$ *JJJ)))))) ; ; ;g!!    ! !#####f###L4 4 4 4 x I 5w ? ? Y 6 @ @ #5?RSSD=D=D=D=D=.D=D=D=N MEMEMEMEME;MEMEME`------rR