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
U
I=®d„rã@s dZddlZddlZddlZddlmZddlmZddlm    Z    ddl
m Z m Z m Z mZmZddlmZmZmZmZdd    lmZmZmZdd
lmZmZdd lmZdd lmZm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddlm+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddlm3Z3ej4dkrVz
ej5Z6Wne7k
rRej8Z6YnXnejZ6efdd„Z9efdd„Z:Gdd„de;ƒZ<Gdd„de<ƒZ=dd„Z>dS)z“
requests.session
~~~~~~~~~~~~~~~~
 
This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
éN)Ú    timedelta)Ú OrderedDicté)Ú_basic_auth_str)Ú    cookielibÚis_py3ÚurljoinÚurlparseÚMapping)Úcookiejar_from_dictÚextract_cookies_to_jarÚRequestsCookieJarÚ merge_cookies)ÚRequestÚPreparedRequestÚDEFAULT_REDIRECT_LIMIT)Ú default_hooksÚ dispatch_hook)Úto_native_string)Úto_key_val_listÚdefault_headersÚ DEFAULT_PORTS)ÚTooManyRedirectsÚ InvalidSchemaÚChunkedEncodingErrorÚContentDecodingError)ÚCaseInsensitiveDict)Ú HTTPAdapter)Ú requote_uriÚget_environ_proxiesÚget_netrc_authÚshould_bypass_proxiesÚget_auth_from_urlÚ rewind_body)Úcodes)ÚREDIRECT_STATIÚwin32cCsp|dkr |S|dkr|St|tƒr,t|tƒs0|S|t|ƒƒ}| t|ƒ¡dd„| ¡Dƒ}|D]
}||=q`|S)zèDetermines appropriate setting for a given request, taking into account
    the explicit setting on that request, and the setting in the session. If a
    setting is a dictionary, they will be merged together using `dict_class`
    NcSsg|]\}}|dkr|‘qS©N©)Ú.0ÚkÚvr(r(úTD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_vendor/requests/sessions.pyÚ
<listcomp>Jsz!merge_setting.<locals>.<listcomp>)Ú
isinstancer
rÚupdateÚitems)Úrequest_settingÚsession_settingÚ
dict_classÚmerged_settingÚ    none_keysÚkeyr(r(r,Ú merge_setting2sÿþ r7cCs@|dks| d¡gkr|S|dks0| d¡gkr4|St|||ƒS)z©Properly merges both requests and session hooks.
 
    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    NÚresponse)Úgetr7)Ú request_hooksÚ session_hooksr3r(r(r,Ú merge_hooksQs
r<c@s>eZdZdd„Zdd„Zddd    „Zd
d „Zd d „Zdd„ZdS)ÚSessionRedirectMixincCs,|jr(|jd}tr| d¡}t|dƒSdS)z7Receives a Response. Returns a redirect URI or ``None``ÚlocationÚlatin1Úutf8N)Ú is_redirectÚheadersrÚencoder)ÚselfÚrespr>r(r(r,Úget_redirect_targetbs 
 
 
z(SessionRedirectMixin.get_redirect_targetcCsšt|ƒ}t|ƒ}|j|jkr dS|jdkrL|jdkrL|jdkrL|jdkrLdS|j|jk}|j|jk}t |jd¡df}|s’|j|kr’|j|kr’dS|p˜|S)zFDecide whether Authorization header should be removed when redirectingTÚhttp)éPNÚhttps)i»NFN)r    ÚhostnameÚschemeÚportrr9)rDÚold_urlÚnew_urlÚ
old_parsedÚ
new_parsedÚ changed_portÚchanged_schemeÚ default_portr(r(r,Úshould_strip_authws$ ÿÿ  ÿz&SessionRedirectMixin.should_strip_authFNTc    
ksHg}
| |¡} t|jƒj} | rD| ¡} |
 |¡|
dd…|_z
|jWn(tt    t
fk
rr|j j ddYnXt |jƒ|jkr˜td |j¡|d‚| ¡|  d¡rÈt|jƒ}d t|jƒ| g¡} t| ƒ}|jd    krì| rì|j| d
}n |jrø|j} | ¡} |jst|jt| ƒƒ} nt| ƒ} t| ƒ| _| | |¡|jtjtjfkrpd }|D]}| j  !|d¡qTd| _"| j }| !d d¡t#| j$||j ƒt%| j$|j&ƒ|  '| j$¡| (| |¡}| )| |¡| j*dk    oàd |kpàd|k}|rðt+| ƒ| }|r|Vq|j,|f|||||ddœ|    —Ž}t#|j&| |j ƒ| |¡} |VqdS)zBReceives a Response. Returns a generator of Responses or Requests.rNF)Údecode_contentzExceeded {} redirects.)r8z//ú:Ú)Úfragment)úContent-Lengthz Content-TypeúTransfer-EncodingÚCookierYrZ)ÚstreamÚtimeoutÚverifyÚcertÚproxiesÚallow_redirects)-rFr    ÚurlrXÚcopyÚappendÚhistoryÚcontentrrÚ RuntimeErrorÚrawÚreadÚlenÚ max_redirectsrÚformatÚcloseÚ
startswithÚjoinrrKÚ_replaceÚgeturlÚnetlocrrÚrebuild_methodÚ status_coder$Útemporary_redirectÚpermanent_redirectrBÚpopÚbodyr Ú_cookiesrÚcookiesÚprepare_cookiesÚrebuild_proxiesÚ rebuild_authÚ_body_positionr#Úsend)rDrEÚreqr\r]r^r_r`Úyield_requestsÚadapter_kwargsÚhistrbÚprevious_fragmentÚprepared_requestÚ parsed_rurlÚparsedÚpurged_headersÚheaderrBÚ
rewindabler(r(r,Úresolve_redirectss~
 
 
 
 
 
      þÿùø 
z&SessionRedirectMixin.resolve_redirectscCsR|j}|j}d|kr*| |jj|¡r*|d=|jr8t|ƒnd}|dk    rN| |¡dS)zéWhen being redirected we may want to strip authentication from the
        request to avoid leaking credentials. This method intelligently removes
        and reapplies authentication where possible to avoid credential loss.
        Ú AuthorizationN)rBrbrTÚrequestÚ    trust_envr Ú prepare_auth)rDr…r8rBrbÚnew_authr(r(r,r}þsz!SessionRedirectMixin.rebuild_authc CsÖ|dk    r |ni}|j}|j}t|ƒj}| ¡}| d¡}t||d}|jr||s|t||d}    |     ||     d¡¡}
|
r||     ||
¡d|krŠ|d=zt
||ƒ\} } Wnt k
rºd\} } YnX| rÒ| rÒt | | ƒ|d<|S)a°This method re-evaluates the proxy configuration by considering the
        environment variables. If we are redirected to a URL covered by
        NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
        proxy keys for this URL (in case they were stripped by a previous
        redirect).
 
        This method also replaces the Proxy-Authorization header where
        necessary.
 
        :rtype: dict
        NÚno_proxy©r‘ÚallzProxy-Authorization)NN) rBrbr    rKrcr9r!rŽrÚ
setdefaultr"ÚKeyErrorr) rDr…r`rBrbrKÚ new_proxiesr‘Ú bypass_proxyÚenviron_proxiesÚproxyÚusernameÚpasswordr(r(r,r|s* 
 
 
  z$SessionRedirectMixin.rebuild_proxiescCsX|j}|jtjkr|dkrd}|jtjkr6|dkr6d}|jtjkrN|dkrNd}||_dS)z‚When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        ÚHEADÚGETÚPOSTN)Úmethodrtr$Ú    see_otherÚfoundÚmoved)rDr…r8rŸr(r(r,rs:sz#SessionRedirectMixin.rebuild_method)FNTNNF)    Ú__name__Ú
__module__Ú __qualname__rFrTr‹r}r|rsr(r(r(r,r=`sÿ
n)r=c@sÌeZdZdZdddddddd    d
d d d g Zdd„Zdd„Zdd„Zdd„Zd6dd„Z    dd„Z
dd„Z dd„Z d7d d!„Z d8d"d#„Zd9d$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„ZdS):ÚSessiona€A Requests session.
 
    Provides cookie persistence, connection-pooling, and configuration.
 
    Basic Usage::
 
      >>> import requests
      >>> s = requests.Session()
      >>> s.get('https://httpbin.org/get')
      <Response [200]>
 
    Or as a context manager::
 
      >>> with requests.Session() as s:
      ...     s.get('https://httpbin.org/get')
      <Response [200]>
    rBrzÚauthr`ÚhooksÚparamsr^r_Úadaptersr\rŽrkcCsrtƒ|_d|_i|_tƒ|_i|_d|_d|_d|_    t
|_ d|_ t iƒ|_tƒ|_| dtƒ¡| dtƒ¡dS)NFTzhttps://zhttp://)rrBr§r`rr¨r©r\r^r_rrkrŽr rzrrªÚmountr©rDr(r(r,Ú__init__js
zSession.__init__cCs|Sr'r(r¬r(r(r,Ú    __enter__¡szSession.__enter__cGs | ¡dSr')rm)rDÚargsr(r(r,Ú__exit__¤szSession.__exit__c Cs²|jpi}t|tjƒst|ƒ}tttƒ|jƒ|ƒ}|j}|jrR|sR|jsRt    |j
ƒ}t ƒ}|j |j  ¡|j
|j|j|jt|j|jtdt|j|jƒt||jƒ|t|j|jƒd
|S)a‹Constructs a :class:`PreparedRequest <PreparedRequest>` for
        transmission and returns it. The :class:`PreparedRequest` has settings
        merged from the :class:`Request <Request>` instance and those of the
        :class:`Session`.
 
        :param request: :class:`Request` instance to prepare with this
            session's settings.
        :rtype: requests.PreparedRequest
        )r3)
rŸrbÚfilesÚdataÚjsonrBr©r§rzr¨)rzr.rÚ    CookieJarr rr r§rŽr rbrÚpreparerŸÚupperr±r²r³r7rBrr©r<r¨)rDrrzÚmerged_cookiesr§Úpr(r(r,Úprepare_request§s0
 
  ÿ
 
 ö zSession.prepare_requestNTc Cstt| ¡||||pi||pi||| d
}| |¡}| p8i} | |j| | ||¡}|    |
dœ}| |¡|j|f|Ž}|S)aConstructs a :class:`Request <Request>`, prepares it and sends it.
        Returns :class:`Response <Response>` object.
 
        :param method: method for the new :class:`Request` object.
        :param url: URL for the new :class:`Request` object.
        :param params: (optional) Dictionary or bytes to be sent in the query
            string for the :class:`Request`.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the
            :class:`Request`.
        :param headers: (optional) Dictionary of HTTP Headers to send with the
            :class:`Request`.
        :param cookies: (optional) Dict or CookieJar object to send with the
            :class:`Request`.
        :param files: (optional) Dictionary of ``'filename': file-like-objects``
            for multipart encoding upload.
        :param auth: (optional) Auth tuple or callable to enable
            Basic/Digest/Custom HTTP Auth.
        :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 allow_redirects: (optional) Set to True by default.
        :type allow_redirects: bool
        :param proxies: (optional) Dictionary mapping protocol or protocol and
            hostname to the URL of the proxy.
        :param stream: (optional) whether to immediately download the response
            content. Defaults to ``False``.
        :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. Defaults to ``True``.
        :param cert: (optional) if String, path to ssl client cert file (.pem).
            If Tuple, ('cert', 'key') pair.
        :rtype: requests.Response
        )
rŸrbrBr±r²r³r©r§rzr¨)r]ra)rr¶r¹Úmerge_environment_settingsrbr/r)rDrŸrbr©r²rBrzr±r§r]rar`r¨r\r^r_r³r€ÚprepÚsettingsÚ send_kwargsrEr(r(r,rÏs6)ö
ÿþ
zSession.requestcKs| dd¡|jd|f|ŽS)zåSends a GET request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        raTr©r”r©rDrbÚkwargsr(r(r,r9s z Session.getcKs| dd¡|jd|f|ŽS)zéSends a OPTIONS request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        raTÚOPTIONSr¾r¿r(r(r,Úoptions!s zSession.optionscKs| dd¡|jd|f|ŽS)zæSends a HEAD request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        raFrœr¾r¿r(r(r,Úhead,s z Session.headcKs|jd|f||dœ|—ŽS)aÈSends a POST request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        rž)r²r³©r)rDrbr²r³rÀr(r(r,Úpost7s z Session.postcKs|jd|fd|i|—ŽS)auSends a PUT request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        ÚPUTr²rÄ©rDrbr²rÀr(r(r,ÚputDs
z Session.putcKs|jd|fd|i|—ŽS)awSends a PATCH request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        ÚPATCHr²rÄrÇr(r(r,ÚpatchPs
z Session.patchcKs|jd|f|ŽS)zèSends a DELETE request. Returns :class:`Response` object.
 
        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        ÚDELETErÄr¿r(r(r,Údelete\szSession.deletec Ks|| d|j¡| d|j¡| d|j¡| d|j¡t|tƒrJtdƒ‚| dd¡}|     d¡}|j
}|j |j d}t ƒ}|j|f|Ž}t ƒ|}    t|    d    |_td
||f|Ž}|jrÒ|jD]}
t|j|
j|
jƒqºt|j||jƒ|r|j||f|Ž} d d „| Dƒ} ng} | r,|  d |¡|  ¡}| |_|slz"t|j||fddi|—Žƒ|_Wntk
rjYnX|sx|j|S)zISend a given PreparedRequest.
 
        :rtype: requests.Response
        r\r^r_r`z#You can only send PreparedRequests.raT)rb)Úsecondsr8cSsg|]}|‘qSr(r()r)rEr(r(r,r-™sz Session.send.<locals>.<listcomp>rr)r”r\r^r_r`r.rÚ
ValueErrorrwr9r¨Ú get_adapterrbÚpreferred_clockrrÚelapsedrrer rzrrhr‹ÚinsertÚnextÚ_nextÚ StopIterationrf) rDrrÀrar\r¨ÚadapterÚstartÚrrÑrEÚgenrer(r(r,rfsF
 
 
 
 "z Session.sendc
Cs¬|jrn|dk    r| d¡nd}t||d}| ¡D]\}}    | ||    ¡q0|dksV|dkrntj d¡pltj d¡}t||jƒ}t||j    ƒ}t||j
ƒ}t||j ƒ}||||dœS)z^
        Check the environment and merge it with some settings.
 
        :rtype: dict
        Nr‘r’TÚREQUESTS_CA_BUNDLEÚCURL_CA_BUNDLE)r^r`r\r_) rŽr9rr0r”ÚosÚenvironr7r`r\r^r_)
rDrbr`r\r^r_r‘Ú env_proxiesr*r+r(r(r,rº±s   
ÿ    ÿz"Session.merge_environment_settingscCs@|j ¡D]"\}}| ¡ | ¡¡r
|Sq
td |¡ƒ‚dS)z~
        Returns the appropriate connection adapter for the given URL.
 
        :rtype: requests.adapters.BaseAdapter
        z*No connection adapters were found for {!r}N)rªr0Úlowerrnrrl)rDrbÚprefixrÖr(r(r,rÏÎs
zSession.get_adaptercCs|j ¡D] }| ¡q
dS)z+Closes all adapters and as such the sessionN)rªÚvaluesrm)rDr+r(r(r,rmÜsz Session.closecs>||jˆ<‡fdd„|jDƒ}|D]}|j |¡|j|<q"dS)zwRegisters a connection adapter to a prefix.
 
        Adapters are sorted in descending order by prefix length.
        cs g|]}t|ƒtˆƒkr|‘qSr()rj)r)r*©ràr(r,r-çsz!Session.mount.<locals>.<listcomp>N)rªrw)rDràrÖÚ keys_to_mover6r(râr,r«ás
z Session.mountcs‡fdd„ˆjDƒ}|S)Ncsi|]}|tˆ|dƒ“qSr')Úgetattr)r)Úattrr¬r(r,Ú
<dictcomp>ísz(Session.__getstate__.<locals>.<dictcomp>)Ú    __attrs__)rDÚstater(r¬r,Ú __getstate__ìszSession.__getstate__cCs"| ¡D]\}}t|||ƒqdSr')r0Úsetattr)rDrèråÚvaluer(r(r,Ú __setstate__ðszSession.__setstate__)NNNNNNNTNNNNNN)NN)N)N)r£r¤r¥Ú__doc__rçr­r®r°r¹rr9rÂrÃrÅrÈrÊrÌrrºrÏrmr«rérìr(r(r(r,r¦Qs^ý7)ý
G  
 
 
 
K r¦cCstƒS)aZ
    Returns a :class:`Session` for context-management.
 
    .. deprecated:: 1.0.0
 
        This method has been deprecated since version 1.0.0 and is only kept for
        backwards compatibility. New code should use :class:`~requests.sessions.Session`
        to create a session. This may be removed at a future date.
 
    :rtype: Session
    )r¦r(r(r(r,Úsessionõs rî)?rírÜÚsysÚtimeÚdatetimerÚ collectionsrr§rÚcompatrrrr    r
rzr r r rÚmodelsrrrr¨rrÚ_internal_utilsrÚutilsrrrÚ
exceptionsrrrrÚ
structuresrrªrrrr r!r"r#Ú status_codesr$r%ÚplatformÚ perf_counterrÐÚAttributeErrorZclockr7r<Úobjectr=r¦rîr(r(r(r,Ú<module>sB          
  r'