zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
U
 ý°dVã@sžddlmZddlZddlZddlZddlZddlmZddlm    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)dddgZ*e +e,¡Z-dZ.dZ/e 0d¡Z1Gdd„dej2ƒZ3ddddœdd„Z4e 5e4e3¡e 5e4e3¡dœZ6eedœZ7Gd d„de ƒZ8Gd!d„de8ƒZ9d"d#dd$œd%d„Z:dS)&é)Ú annotationsN)Ú TracebackType)Úurljoiné)Ú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)ÚLiteralÚ PoolManagerÚ ProxyManagerÚproxy_from_url) Úkey_fileÚ    cert_fileÚ    cert_reqsÚca_certsÚ ssl_versionZssl_minimum_versionZssl_maximum_versionÚ ca_cert_dirÚ ssl_contextÚ key_passwordÚserver_hostnamei@Ú_SelfTc@sò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_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_certszint | str | NoneÚkey_ssl_versionzssl.TLSVersion | NoneZkey_ssl_minimum_versionZkey_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 | NoneZkey__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__©rJrJúJd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\urllib3/poolmanager.pyr%9s:
r%z type[PoolKey]údict[str, typing.Any])Ú    key_classÚrequest_contextÚreturncCsØ| ¡}|d ¡|d<|d ¡|d<dD],}||kr,||dk    r,t|| ¡ƒ||<q,| d¡}|dk    rxt|ƒ|d<t| ¡ƒD]}| |¡|d|<q„|j    D]}||kr¢d||<q¢| d¡dkrÎt
|d<|f|Ž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_rD) ÚcopyÚlowerÚ    frozensetÚitemsÚgetÚtupleÚlistÚkeysÚpopÚ_fieldsÚ_DEFAULT_BLOCKSIZE)rMrNÚcontextÚkeyÚ socket_optsÚfieldrJrJrKÚ_default_key_normalizer_s"
 
 
rf©ÚhttpÚhttpscseZdZUdZdZded<dZded<dAdd    d
d d œ‡fd d„ Zdddœdd„Zdddddœdd„Z    dBddddddœdd„Z
d d œd!d"„Z dCd$d%d$ddd&œd'd(„Z d)dd*œd+d,„Z d-d)dd.œd/d0„ZdDdddd1œd2d3„Zdd)d4œd5d6„Zd7d8d9œd:d;„ZdEddd8d
d=d>œd?d@„Z‡ZS)FraV
    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
 
    Nr;Úproxyr>Ú proxy_configé
Úintútyping.Mapping[str, str] | Noneú
typing.AnyÚNone)Ú    num_poolsrRÚconnection_pool_kwrOc s4tƒ |¡||_|t|ƒ|_t|_t ¡|_dS©N)ÚsuperÚ__init__rrrÚpoolsÚpool_classes_by_schemeÚkey_fn_by_schemerW)ÚselfrqrRrr©Ú    __class__rJrKruÇs  
zPoolManager.__init__r$)ryrOcCs|SrsrJ©ryrJrJrKÚ    __enter__ØszPoolManager.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | NonezLiteral[False])Úexc_typeÚexc_valÚexc_tbrOcCs | ¡dS)NF)Úclear)ryr~rr€rJrJrKÚ__exit__ÛszPoolManager.__exit__r&údict[str, typing.Any] | Noner    )rPrQÚportrNrOcCst|j|}|dkr|j ¡}| d¡dkr2t|d<dD]}| |d¡q6|dkrftD]}| |d¡qT|||f|Ž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)rPrQr„rh)rwrrrWr[rar_Ú SSL_KEYWORDS)ryrPrQr„rNÚpool_clsrcÚkwrJrJrKÚ    _new_poolås
 
zPoolManager._new_pool)rOcCs|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)rvrr|rJrJrKr szPoolManager.clearrhr/r)©rQr„rPÚ pool_kwargsrOcCsT|s tdƒ‚| |¡}|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.rhrPéPr„rQ)r Ú_merge_pool_kwargsr r[rXÚconnection_from_context)ryrQr„rPr‹rNrJrJrKÚconnection_from_hosts
 z PoolManager.connection_from_hostrL)rNrOcCsXd|krt dt¡| d¡|d ¡}|j |¡}|sBt|ƒ‚||ƒ}|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.
        ÚstrictzdThe 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v2.1.0.rP©rN)    ÚwarningsÚwarnÚDeprecationWarningr_rXrxr[rÚconnection_from_pool_key)ryrNrPÚpool_key_constructorÚpool_keyrJrJrKrŽ1s    ý
  z#PoolManager.connection_from_contextr%)r—rNrOc
Csl|jjZ|j |¡}|r*|W5QR£S|d}|d}|d}|j||||d}||j|<W5QRX|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.
        rPrQr„r‘)rvÚlockr[r‰)ryr—rNÚpoolrPrQr„rJrJrKr•Js
 
 z$PoolManager.connection_from_pool_key)Úurlr‹rOcCs 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.
        )r„rPr‹)rrrQr„rP)ryršr‹ÚurJrJrKÚconnection_from_urlds ÿzPoolManager.connection_from_url)ÚoverriderOc    CsV|j ¡}|rR| ¡D]:\}}|dkrHz
||=WqPtk
rDYqPXq|||<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)rrrWrZÚKeyError)ryrÚbase_pool_kwargsrcÚvaluerJrJrKrvs
 
 
 
zPoolManager._merge_pool_kwargsrÚbool)Ú
parsed_urlrOcCs"|jdkrdSt|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)rjrrkrP)ryr¢rJrJrKÚ!_proxy_requires_url_absolute_formŒs
ÿz-PoolManager._proxy_requires_url_absolute_formTr©ÚmethodršÚredirectrˆrOc Ks†t|ƒ}|j|j|j|jd}d|d<d|d<d|kr@|j|d<| |¡r\|j||f|Ž}n|j||jf|Ž}|ox|     ¡}|s‚|St
||ƒ}|j dkršd}|  d¡}    t |    tƒs¼tj|    |d    }    |    jr | |¡s |d ¡}
|dD]} |  ¡|    jkrä|
 | d
¡qä|
|d<z|    j||||d }    Wn,tk
rN|    jrF| ¡‚|YSX|    |d<||d<t d ||¡| ¡|j||f|Ž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.
        )r„rPFÚassert_same_hostr¦rRi/ÚGETÚretries)r¦N)ÚresponseÚ_poolzRedirecting %s -> %s)rrrQr„rPrRr£ÚurlopenÚ request_uriÚget_redirect_locationrÚstatusr[Ú
isinstancerÚfrom_intÚremove_headers_on_redirectÚ is_same_hostrWrXr_Ú    incrementr Úraise_on_redirectÚ
drain_connÚlogÚinfo) ryr¥ršr¦rˆr›ÚconnrªÚredirect_locationr©Ú new_headersÚheaderrJrJrKr¬™sL 
 
 
 
 
 
 ÿ  
zPoolManager.urlopen)rlN)N)NrhN)N)T)rErFrGrHrjrIrkrur}r‚r‰rrrŽr•rœrr£r¬Ú __classcell__rJrJrzrKr¢s.
!  ýû& ûÿÿc s†eZdZdZd!dddddd    d
d d d dœ
‡fdd„ Zd"d dd dddœ‡fdd„ Zd#ddddœdd„Zd$ddd    d ddœ‡fdd „ Z‡ZS)%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
 
    rlNFr&rmrnr7r¡zNone | str | Literal[False]r/rorp)
Ú    proxy_urlrqrRÚ proxy_headersÚproxy_ssl_contextÚuse_forwarding_for_httpsÚproxy_assert_hostnameÚproxy_assert_fingerprintrrrOc      sÀt|tƒr&|j›d|j›d|j›}
n|}
t|
ƒ} | jdkrFt| jƒ‚| jsft | jd¡} | j    | d} | |_
|pri|_ ||_ t ||||ƒ|_|j
|    d<|j |    d<|j|    d<tƒj||f|    ŽdS)    Nz://ú:rgrŒ)r„Ú_proxyrSZ _proxy_config)r°r    rPrQr„rrr r[Ú_replacerjr¿rÀrrkrtru) ryr¾rqrRr¿rÀrÁrÂrÃrrZ str_proxy_urlrjr„rzrJrKrus,
 
 
 
ü
 
 
zProxyManager.__init__rhr)rƒr    rŠcs<|dkrtƒj||||dStƒj|jj|jj|jj|dS)Nri)r‹)rtrrjrQr„rP)ryrQr„rPr‹rzrJrKr?sÿÿz!ProxyManager.connection_from_hostztyping.Mapping[str, str])ršrRrOcCs0ddi}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)rÚnetlocÚupdate)ryršrRÚheaders_rÉrJrJrKÚ_set_proxy_headersOs
 
zProxyManager._set_proxy_headersTrr¤c sRt|ƒ}t|j|j|jƒs8| d|j¡}| ||¡|d<tƒj    ||fd|i|—ŽS)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rRr¦)
rrrjrkrPr[rRrÌrtr¬)ryr¥ršr¦rˆr›rRrzrJrKr¬`s
zProxyManager.urlopen)rlNNNFNN)NrhN)N)T)    rErFrGrHrurrÌr¬r½rJrJrzrKrßs"9÷&,ûÿÿr&ro)ršrˆrOcKstfd|i|—ŽS)Nr¾)r)ršrˆrJrJrKros);Ú
__future__rÚ    functoolsÚloggingÚtypingr’ÚtypesrÚ urllib.parserÚ _collectionsrZ_request_methodsrÚ
connectionrÚconnectionpoolr    r
r Ú
exceptionsr r rrrªrZutil.connectionrZ
util.proxyrZ
util.retryrZ util.timeoutrZutil.urlrrÚ TYPE_CHECKINGÚsslZtyping_extensionsrÚ__all__Ú    getLoggerrEr·r†raÚTypeVarr$Ú
NamedTupler%rfÚpartialrxrwrrrrJrJrJrKÚ<module>sJ            
 
 
&<
 
þ
?