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
U
I=®dÅEã@s(ddlmZddlZddlZddlZddlZddlmZddlm    Z    m
Z
ddlm Z ddl m Z mZmZmZddlmZdd    lmZdd
lmZdd lmZdd lmZd ddgZe e¡ZdZdZ e !de ¡Z"dd„Z#e $e#e"¡e $e#e"¡dœZ%e    e
dœZ&Gdd „d eƒZ'Gdd„de'ƒZ(dd„Z)dS)é)Úabsolute_importNé)ÚRecentlyUsedContainer)ÚHTTPConnectionPoolÚHTTPSConnectionPool)Úport_by_scheme)ÚLocationValueErrorÚ MaxRetryErrorÚProxySchemeUnknownÚ InvalidProxyConfigurationWarning)Úsix)Úurljoin)ÚRequestMethods)Ú    parse_url)ÚRetryÚ PoolManagerÚ ProxyManagerÚproxy_from_url)Úkey_fileÚ    cert_fileÚ    cert_reqsÚca_certsÚ ssl_versionÚ ca_cert_dirÚ ssl_contextÚ key_password)Ú
key_schemeÚkey_hostÚkey_portÚ key_timeoutÚ key_retriesÚ
key_strictÚ    key_blockÚkey_source_addressÚ key_key_fileÚkey_key_passwordÚ key_cert_fileÚ key_cert_reqsÚ key_ca_certsÚkey_ssl_versionÚkey_ca_cert_dirÚkey_ssl_contextÚ key_maxsizeÚ key_headersÚ
key__proxyÚkey__proxy_headersÚkey_socket_optionsÚkey__socks_optionsÚkey_assert_hostnameÚkey_assert_fingerprintÚkey_server_hostnameÚPoolKeycCsÂ| ¡}|d ¡|d<|d ¡|d<dD],}||kr,||dk    r,t|| ¡ƒ||<q,| d¡}|dk    rxt|ƒ|d<t| ¡ƒD]}| |¡|d|<q„|j    D]}||kr¢d||<q¢|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_)
ÚcopyÚlowerÚ    frozensetÚitemsÚgetÚtupleÚlistÚkeysÚpopÚ_fields)Ú    key_classÚrequest_contextÚcontextÚkeyÚ socket_optsÚfield©rMúVD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_vendor/urllib3/poolmanager.pyÚ_default_key_normalizerJs
 
 
rO©ÚhttpÚhttpsc@sxeZdZdZdZddd„Zdd„Zdd    „Zdd
d „Zd d „Z    ddd„Z
dd„Z ddd„Z d dd„Z dd„Zd!dd„ZdS)"ra$
    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::
 
        >>> manager = PoolManager(num_pools=2)
        >>> r = manager.request('GET', 'http://google.com/')
        >>> r = manager.request('GET', 'http://google.com/mail')
        >>> r = manager.request('GET', 'http://yahoo.com/')
        >>> len(manager.pools)
        2
 
    Né
cKs8t ||¡||_t|dd„d|_t|_t ¡|_dS)NcSs| ¡S©N)Úclose)ÚprMrMrNÚ<lambda>¨óz&PoolManager.__init__.<locals>.<lambda>)Ú dispose_func)rÚ__init__Úconnection_pool_kwrÚpoolsÚpool_classes_by_schemeÚkey_fn_by_schemer=)ÚselfÚ    num_poolsr8r[rMrMrNrZ¥s
 zPoolManager.__init__cCs|SrTrM©r_rMrMrNÚ    __enter__¯szPoolManager.__enter__cCs | ¡dS)NF)Úclear)r_Úexc_typeÚexc_valÚexc_tbrMrMrNÚ__exit__²szPoolManager.__exit__cCs^|j|}|dkr|j ¡}dD]}| |d¡q |dkrPtD]}| |d¡q>|||f|ŽS)a·
        Create a new :class:`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)r6r7ÚportrQ)r]r[r=rEÚ SSL_KEYWORDS)r_r6r7rhrHÚpool_clsrJÚkwrMrMrNÚ    _new_pool·s
 
 
zPoolManager._new_poolcCs|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)r\rcrarMrMrNrcÒszPoolManager.clearrQcCsT|s tdƒ‚| |¡}|pd|d<|s:t |d ¡d¡}||d<||d<| |¡S)a
        Get a :class:`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.rQr6éPrhr7)rÚ_merge_pool_kwargsrrAr>Úconnection_from_context)r_r7rhr6Ú pool_kwargsrHrMrMrNÚconnection_from_hostÛs 
 z PoolManager.connection_from_hostcCs,|d ¡}|j|}||ƒ}|j||dS)zâ
        Get a :class:`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.
        r6©rH)r>r^Úconnection_from_pool_key)r_rHr6Úpool_key_constructorÚpool_keyrMrMrNroòs 
z#PoolManager.connection_from_contextc
Csl|jjZ|j |¡}|r*|W5QR£S|d}|d}|d}|j||||d}||j|<W5QRX|S)zû
        Get a :class:`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.
        r6r7rhrr)r\ÚlockrArl)r_rurHÚpoolr6r7rhrMrMrNrsÿs
 z$PoolManager.connection_from_pool_keycCs 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.
        )rhr6rp)rrqr7rhr6)r_ÚurlrpÚurMrMrNÚconnection_from_urls ÿzPoolManager.connection_from_urlc    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)r[r=r@ÚKeyError)r_ÚoverrideÚbase_pool_kwargsrJÚvaluerMrMrNrn's
 
 
zPoolManager._merge_pool_kwargsTc Ks’t|ƒ}|j|j|j|jd}d|d<d|d<d|krD|j ¡|d<|jdk    rj|jdkrj|j||f|Ž}n|j||j    f|Ž}|o†| 
¡}|s|St ||ƒ}|j dkr¨d    }|  d
¡}    t|    tƒsÊtj|    |d }    |    jr| |¡stt |d¡ƒ}
|
D]"} |  ¡|    jkrô|d | d¡qôz|    j||||d }    Wn,tk
rZ|    jrR| ¡‚|YSX|    |d
<||d<t d ||¡| ¡|j||f|ŽS)a]
        Same as :meth:`urllib3.connectionpool.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.
        )rhr6FÚassert_same_hostÚredirectr8NrQi/ÚGETÚretries)r€)ÚresponseÚ_poolzRedirecting %s -> %s)rrqr7rhr6r8r=ÚproxyÚurlopenÚ request_uriÚget_redirect_locationr ÚstatusrAÚ
isinstancerÚfrom_intÚremove_headers_on_redirectÚ is_same_hostrCr Úiterkeysr>rEÚ    incrementr    Úraise_on_redirectÚ
drain_connÚlogÚinfo) r_Úmethodrxr€rkryÚconnrƒÚredirect_locationr‚r8ÚheaderrMrMrNr†;sJ     
 
 
 
 ÿ
zPoolManager.urlopen)rSN)N)NrQN)N)N)T)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r…rZrbrgrlrcrqrorsrzrnr†rMrMrMrNr‡s
 
 
    
 
 
csPeZdZdZd‡fdd„    Zd‡fdd„    Zdd    d
„Zd d „Zd‡fdd„    Z‡Z    S)rax
    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.
 
    Example:
        >>> proxy = urllib3.ProxyManager('http://localhost:3128/')
        >>> r1 = proxy.request('GET', 'http://google.com/')
        >>> r2 = proxy.request('GET', 'http://httpbin.org/')
        >>> len(proxy.pools)
        1
        >>> r3 = proxy.request('GET', 'https://httpbin.org/')
        >>> r4 = proxy.request('GET', 'https://twitter.com/')
        >>> len(proxy.pools)
        3
 
    rSNc s˜t|tƒrd|j|j|jf}t|ƒ}|jsFt |jd¡}|j|d}|jdkrZt    |jƒ‚||_
|pfi|_ |j
|d<|j |d<t t |ƒj||f|ŽdS)Nz
%s://%s:%irm)rhrPÚ_proxyr9)rŠrr6r7rhrrrAÚ_replacer
r…Ú proxy_headersÚsuperrrZ)r_Ú    proxy_urlr`r8ržr[r…rh©Ú    __class__rMrNrZ˜s"    
ý 
 
 
 
 
zProxyManager.__init__rQcsD|dkr tt|ƒj||||dStt|ƒj|jj|jj|jj|dS)NrR)rp)rŸrrqr…r7rhr6)r_r7rhr6rpr¡rMrNrq·s
ÿ
ÿz!ProxyManager.connection_from_hostcCs0ddi}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)r_rxr8Úheaders_r¥rMrMrNÚ_set_proxy_headersÁs
 
zProxyManager._set_proxy_headerscCs(|dkr$|jjdkr$tjdtdddS)NrRaYour proxy configuration specified an HTTPS scheme for the proxy. Are you sure you want to use HTTPS to contact the proxy? This most likely indicates an error in your configuration. Read this issue for more info: https://github.com/urllib3/urllib3/issues/1850é)Ú
stacklevel)r…r6ÚwarningsÚwarnr )r_Ú
url_schemerMrMrNÚ$_validate_proxy_scheme_url_selectionÐs ùz1ProxyManager._validate_proxy_scheme_url_selectionTc sZt|ƒ}| |j¡|jdkr<| d|j¡}| ||¡|d<tt|ƒj||fd|i|—ŽS)z@Same as HTTP(S)ConnectionPool.urlopen, ``url`` must be absolute.rQr8r€)    rr®r6rAr8r¨rŸrr†)r_r”rxr€rkryr8r¡rMrNr†Üs  
zProxyManager.urlopen)rSNN)NrQN)N)T)
r˜r™ršr›rZrqr¨r®r†Ú __classcell__rMrMr¡rNr}sû
 
 cKstfd|i|—ŽS)Nr )r)rxrkrMrMrNrës)*Ú
__future__rÚ collectionsÚ    functoolsÚloggingr«Ú _collectionsrÚconnectionpoolrrrÚ
exceptionsrr    r
r Úpackagesr Zpackages.six.moves.urllib.parser ÚrequestrZutil.urlrZ
util.retryrÚ__all__Ú    getLoggerr˜r’riÚ _key_fieldsÚ
namedtupler5rOÚpartialr^r]rrrrMrMrMrNÚ<module>s6        
 
  6
 
þ
wn