zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
U
¡ý°daLã@s¦dZddlZddlZddlmZmZddlmZddlm    Z
ddlm Z m Z m Z mZddlmZddlmZmZdd    lmZdd
lmZmZdd lmZdd lmZdd lmZddlmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm    Z    m(Z(m)Z)m*Z*mZm+Z+m,Z,mZddl-m.Z.ddl/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8zddl9m:Z:Wne;k
rrdd„Z:YnXdZ<dZ=dZ>dZ?Gdd„dƒZ@Gdd„de@ƒZAdS)z‰
requests.adapters
~~~~~~~~~~~~~~~~~
 
This module contains the transport adapters that Requests uses to define
and maintain connections.
éN)ÚClosedPoolErrorÚConnectTimeoutError)Ú    HTTPError)Ú InvalidHeader)ÚLocationValueErrorÚ MaxRetryErrorÚNewConnectionErrorÚ ProtocolError)Ú
ProxyError)ÚReadTimeoutErrorÚ ResponseError)ÚSSLError)Ú PoolManagerÚproxy_from_url)ÚTimeout)Ú    parse_url)ÚRetryé)Ú_basic_auth_str)Ú
basestringÚurlparse)Úextract_cookies_to_jar)
ÚConnectionErrorÚConnectTimeoutrÚInvalidProxyURLÚ InvalidSchemaÚ
InvalidURLr
Ú ReadTimeoutÚ
RetryErrorr )ÚResponse)ÚCaseInsensitiveDict)ÚDEFAULT_CA_BUNDLE_PATHÚextract_zipped_pathsÚget_auth_from_urlÚget_encoding_from_headersÚprepend_scheme_if_neededÚ select_proxyÚ urldefragauth)ÚSOCKSProxyManagercOs tdƒ‚dS)Nz'Missing dependencies for SOCKS support.)r)ÚargsÚkwargs©r+úHd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\requests/adapters.pyr(<sr(Fé
cs2eZdZdZ‡fdd„Zd dd„Zd    d
„Z‡ZS) Ú BaseAdapterzThe Base Transport Adaptercstƒ ¡dS©N)ÚsuperÚ__init__©Úself©Ú    __class__r+r,r1IszBaseAdapter.__init__FNTcCst‚dS)aCSends PreparedRequest object. Returns Response object.
 
        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        N©ÚNotImplementedError)r3ÚrequestÚstreamÚtimeoutÚverifyÚcertÚproxiesr+r+r,ÚsendLszBaseAdapter.sendcCst‚dS)z!Cleans up adapter specific items.Nr6r2r+r+r,Úclose_szBaseAdapter.close)FNTNN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r1r>r?Ú __classcell__r+r+r4r,r.Fs ÿ
r.cs eZdZdZdddddgZeeeef‡fdd„    Zd    d
„Z    d d „Z
efd d„Z dd„Z dd„Z dd„Zd$dd„Zdd„Zdd„Zdd„Zdd„Zd%d"d#„Z‡ZS)&Ú HTTPAdapteraThe built-in HTTP Adapter for urllib3.
 
    Provides a general-case interface for Requests sessions to contact HTTP and
    HTTPS urls by implementing the Transport Adapter interface. This class will
    usually be created by the :class:`Session <Session>` class under the
    covers.
 
    :param pool_connections: The number of urllib3 connection pools to cache.
    :param pool_maxsize: The maximum number of connections to save in the pool.
    :param max_retries: The maximum number of retries each connection
        should attempt. Note, this applies only to failed DNS lookups, socket
        connections and connection timeouts, never to requests where data has
        made it to the server. By default, Requests does not retry failed
        connections. If you need granular control over the conditions under
        which we retry a request, import urllib3's ``Retry`` class and pass
        that instead.
    :param pool_block: Whether the connection pool should block for connections.
 
    Usage::
 
      >>> import requests
      >>> s = requests.Session()
      >>> a = requests.adapters.HTTPAdapter(max_retries=3)
      >>> s.mount('http://', a)
    Ú max_retriesÚconfigÚ_pool_connectionsÚ _pool_maxsizeÚ _pool_blockcs`|tkrtddd|_n t |¡|_i|_i|_tƒ ¡||_||_    ||_
|j |||ddS)NrF)Úread©Úblock) ÚDEFAULT_RETRIESrrFÚfrom_intrGÚ proxy_managerr0r1rHrIrJÚinit_poolmanager)r3Úpool_connectionsÚ pool_maxsizerFÚ
pool_blockr4r+r,r1‡s 
zHTTPAdapter.__init__cs‡fdd„ˆjDƒS)Ncsi|]}|tˆ|dƒ“qSr/)Úgetattr)Ú.0Úattrr2r+r,Ú
<dictcomp>žsz,HTTPAdapter.__getstate__.<locals>.<dictcomp>)Ú    __attrs__r2r+r2r,Ú __getstate__szHTTPAdapter.__getstate__cCsDi|_i|_| ¡D]\}}t|||ƒq|j|j|j|jddS)NrL)rPrGÚitemsÚsetattrrQrHrIrJ)r3ÚstaterWÚvaluer+r+r,Ú __setstate__ sÿzHTTPAdapter.__setstate__cKs.||_||_||_tf|||dœ|—Ž|_dS)aInitializes a urllib3 PoolManager.
 
        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param connections: The number of urllib3 connection pools to cache.
        :param maxsize: The maximum number of connections to save in the pool.
        :param block: Block when no free connections are available.
        :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
        )Ú    num_poolsÚmaxsizerMN)rHrIrJrÚ poolmanager)r3Ú connectionsrarMÚ pool_kwargsr+r+r,rQ­sýüzHTTPAdapter.init_poolmanagercKs–||jkr|j|}n|| ¡ d¡r^t|ƒ\}}t|f|||j|j|jdœ|—Ž}|j|<n4| |¡}t    |f||j|j|jdœ|—Ž}|j|<|S)aÏReturn urllib3 ProxyManager for the given proxy.
 
        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param proxy: The proxy to return a urllib3 ProxyManager for.
        :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
        :returns: ProxyManager
        :rtype: urllib3.ProxyManager
        Úsocks)ÚusernameÚpasswordr`rarM)Ú proxy_headersr`rarM)
rPÚlowerÚ
startswithr#r(rHrIrJrhr)r3ÚproxyÚ proxy_kwargsÚmanagerrfrgrhr+r+r,Úproxy_manager_forÇs6
  ÿúù
 
ÿûú    zHTTPAdapter.proxy_manager_forcCsü| ¡ d¡rn|rnd}|dk    r"|}|s.ttƒ}|r>tj |¡sLtd|›ƒ‚d|_tj     |¡sf||_
q€||_ nd|_d|_
d|_ |røt |t ƒs¤|d|_|d|_n ||_d|_|jrÔtj |j¡sÔtd    |j›ƒ‚|jrøtj |j¡søtd
|j›ƒ‚dS) aAVerify a SSL certificate. This method should not be called from user
        code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param conn: The urllib3 connection object associated with the cert.
        :param url: The requested URL.
        :param verify: Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: The SSL certificate to verify.
        ÚhttpsNTzCCould not find a suitable TLS CA certificate bundle, invalid path: Ú CERT_REQUIREDÚ    CERT_NONErrz7Could not find the TLS certificate file, invalid path: z/Could not find the TLS key file, invalid path: )rirjr"r!ÚosÚpathÚexistsÚOSErrorÚ    cert_reqsÚisdirÚca_certsÚ ca_cert_dirÚ
isinstancerÚ    cert_fileÚkey_file)r3ÚconnÚurlr;r<Úcert_locr+r+r,Ú cert_verifyís> ÿ 
 
 
ÿ
ÿzHTTPAdapter.cert_verifycCs„tƒ}t|ddƒ|_tt|diƒƒ|_t|jƒ|_||_|jj|_t    |j
t ƒr^|j
  d¡|_
n|j
|_
t |j||ƒ||_||_|S)a¶Builds a :class:`Response <requests.Response>` object from a urllib3
        response. This should not be called from user code, and is only exposed
        for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
 
        :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
        :param resp: The urllib3 response object.
        :rtype: requests.Response
        ÚstatusNÚheaderszutf-8)rrUÚ status_coder r‚r$ÚencodingÚrawÚreasonrzr~ÚbytesÚdecoderÚcookiesr8Ú
connection)r3ÚreqÚrespÚresponser+r+r,Úbuild_response&s
 
 zHTTPAdapter.build_responseNcCsdt||ƒ}|rDt|dƒ}t|ƒ}|js.tdƒ‚| |¡}| |¡}nt|ƒ}| ¡}|j     |¡}|S)aŒReturns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        ÚhttpzFPlease check proxy URL. It is malformed and could be missing the host.)
r&r%rÚhostrrnÚconnection_from_urlrÚgeturlrb)r3r~r=rkÚ    proxy_urlrPr}Úparsedr+r+r,Úget_connectionKs    
 
ÿ
  zHTTPAdapter.get_connectioncCs&|j ¡|j ¡D] }| ¡qdS)z¢Disposes of any internal state.
 
        Currently, this closes the PoolManager and any active ProxyManager,
        which closes any pooled connections.
        N)rbÚclearrPÚvalues)r3rkr+r+r,r?hs
zHTTPAdapter.closec    Cs`t|j|ƒ}t|jƒj}|o"|dk}d}|rDt|ƒj ¡}| d¡}|j}|r\|s\t|jƒ}|S)a?Obtain the url to use when making the final request.
 
        If the message is being sent through a HTTP proxy, the full URL has to
        be used. Otherwise, we should only use the path portion of the URL.
 
        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
        :rtype: str
        roFre)r&r~rÚschemerirjÚpath_urlr')    r3r8r=rkr˜Úis_proxied_http_requestÚusing_socks_proxyÚ proxy_schemer~r+r+r,Ú request_urlrs   
 
zHTTPAdapter.request_urlcKsdS)a"Add any headers needed by the connection. As of v2.0 this does
        nothing by default, but is left for overriding by users that subclass
        the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
        :param kwargs: The keyword arguments from the call to send().
        Nr+)r3r8r*r+r+r,Ú add_headerss zHTTPAdapter.add_headerscCs&i}t|ƒ\}}|r"t||ƒ|d<|S)aReturns a dictionary of the headers to add to any request sent
        through a proxy. This works with urllib3 magic to ensure that they are
        correctly sent to the proxy, rather than in a tunnelled request if
        CONNECT is being used.
 
        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
        :param proxy: The url of the proxy being used for this request.
        :rtype: dict
        zProxy-Authorization)r#r)r3rkr‚rfrgr+r+r,rhs
 zHTTPAdapter.proxy_headersFTc CsÒz| |j|¡}Wn.tk
r@}zt||d‚W5d}~XYnX| ||j||¡| ||¡}    |j||||||d|jdkpˆd|jk }
t    |t
ƒrÖz|\} } t | | d}Wqît k
rÒt d|›dƒ‚YqîXnt    |t ƒrân t ||d}z.|j |j|    |j|jdddd|j||
d     } Wn¨ttfk
rR}zt||d‚W5d}~XYnttk
rö}z†t    |jtƒrŒt    |jtƒsŒt||d‚t    |jtƒr¦t||d‚t    |jtƒrÀt||d‚t    |jtƒrÚt||d‚t||d‚W5d}~XYnÐtk
r$}zt||d‚W5d}~XYn¢tk
rN}z t|ƒ‚W5d}~XYnxttfk
rÄ}zTt    |tƒr~t||d‚n6t    |t ƒr˜t!||d‚nt    |t"ƒr²t#||d‚n‚W5d}~XYnX| $|| ¡S)
aSends PreparedRequest object. Returns Response object.
 
        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple or urllib3 Timeout object
        :param verify: (optional) Either a boolean, in which case it controls whether
            we verify the server's TLS certificate, or a string, in which case it
            must be a path to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        :rtype: requests.Response
        )r8N)r9r:r;r<r=zContent-Length)ÚconnectrKzInvalid timeout za. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same value.F) Úmethodr~Úbodyr‚ÚredirectÚassert_same_hostÚpreload_contentÚdecode_contentÚretriesr:Úchunked)%r•r~rrr€rržr¡r‚rzÚtupleÚ TimeoutSauceÚ
ValueErrorÚurlopenr rFr    rurrr†rrrr rÚ _ProxyErrorr
Ú    _SSLErrorr rÚ
_HTTPErrorr rÚ_InvalidHeaderrrŽ)r3r8r9r:r;r<r=r}Úer~r§rŸrKrŒÚerrr+r+r,r>²s„ ú    
 
ÿ 
 õ        zHTTPAdapter.send)N)FNTNN)r@rArBrCrYÚDEFAULT_POOLSIZErNÚDEFAULT_POOLBLOCKr1rZr_rQrnr€rŽr•r?rržrhr>rDr+r+r4r,rEds<û
ûÿ
&9%
 
ÿrE)BrCÚos.pathrrÚsocketZurllib3.exceptionsrrrr®rr¯rrrr    r
r¬r r r r­Zurllib3.poolmanagerrrZ urllib3.utilrr©rZurllib3.util.retryrÚauthrÚcompatrrr‰rÚ
exceptionsrrrrrrrÚmodelsrÚ
structuresr Úutilsr!r"r#r$r%r&r'Zurllib3.contrib.socksr(Ú ImportErrorr³r²rNÚDEFAULT_POOL_TIMEOUTr.rEr+r+r+r,Ú<module>s<         0  $