Files
PowerToys/PythonHome/Lib/site-packages/requests/sessions.pyc

178 lines
19 KiB
Plaintext
Raw Normal View History

2014-07-09 18:15:23 +08:00
<03>
G<12>Sc@s<>dZddlZddlmZddlmZddlmZddlmZm Z m
Z
m Z m Z ddl mZmZmZmZdd lmZmZmZdd
lmZmZdd lmZmZmZdd lmZmZm Z m!Z!dd l"m#Z#ddl$m%Z%ddlm&Z&m'Z'm(Z(m)Z)m*Z*ddl+m,Z,ddlm-Z-e d<00>Z.e d<00>Z/de0fd<00><00>YZ1de1fd<00><00>YZ2d<00>Z3dS(s<>
requests.session
~~~~~~~~~~~~~~~~
This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
i<EFBFBD><EFBFBD><EFBFBD><EFBFBD>N(tMapping(tdatetimei(t_basic_auth_str(t cookielibt OrderedDictturljointurlparset builtin_str(tcookiejar_from_dicttextract_cookies_to_jartRequestsCookieJart merge_cookies(tRequesttPreparedRequesttDEFAULT_REDIRECT_LIMIT(t default_hookst dispatch_hook(tto_key_val_listtdefault_headerstto_native_string(tTooManyRedirectst InvalidSchematChunkedEncodingErrortContentDecodingError(tCaseInsensitiveDict(t HTTPAdapter(t requote_uritget_environ_proxiestget_netrc_authtshould_bypass_proxiestget_auth_from_url(tcodes(tREDIRECT_STATIcCs<>|dkr|S|dkr |St|t<00>o;t|t<00>sB|S|t|<00><00>}|jt|<00><00>x0|j<00>D]"\}}|dkrt||=qtqtWtd<00>|j<00>D<><00>}|S(s<>
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`
css-|]#\}}|dk r||fVqdS(N(tNone(t.0tktv((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pys <genexpr>CsN(R!t
isinstanceRRtupdatetitemstdict(trequest_settingtsession_settingt
dict_classtmerged_settingR#R$((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt merge_setting's   cCsZ|dks!|jd<00>gkr%|S|dksF|jd<00>gkrJ|St|||<00>S(s<>
Properly merges both requests and session hooks.
This is necessary because when request_hooks == {'response': []}, the
merge breaks Session hooks entirely.
tresponseN(R!tgetR-(t request_hookst session_hooksR+((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt merge_hooksHs
!!tSessionRedirectMixincBs2eZededdd<00>Zd<00>Zd<00>ZRS(ccs<>d}x<>|jr<>|j<00>} y |jWn-tttfk
rX|jjdt<00>nX||j kr~t
d|j <16><00>n|j <00>|j d}
|j } |
jd<00>r<>t|j<00>} d| j|
f}
nt|
<00>} | j<00>}
t|
<00>jst|jt|
<00><00>}
n t|
<00>}
t|
<00>| _|jtjkrV| dkrVd} n|jtjkr}| dkr}d} n|jtjkr<>| d kr<>d} n| | _ |jtjtjfkr<>d
| j kr<>| j d
=nd| _n| j }y |d =Wnt k
rnXt!| j"| |j<00>| j"j#|j$<00>| j%| j"<00>|j&| |<00>}|j'| |<00>| }|j(|d |d |d|d|d|dt<00>}t!|j$| |j<00>|d7}|Vq WdS(s6Receives a Response. Returns a generator of Responses.itdecode_contentsExceeded %s redirects.tlocations//s%s:%stHEADtGETtPOSTsContent-LengthtCookietstreamttimeouttverifytcerttproxiestallow_redirectsiN()t is_redirecttcopytcontentRRt RuntimeErrortrawtreadtFalset max_redirectsRtclosetheaderstmethodt
startswithRturltschemetgeturltnetlocRRRt status_codeRt see_othertfoundtmovedt temporarytresumeR!tbodytKeyErrorR t_cookiesR&tcookiestprepare_cookiestrebuild_proxiest rebuild_authtsend(tselftresptreqR:R;R<R=R>titprepared_requestRLRJt parsed_rurltparsedRI((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytresolve_redirectsYsn   
                
cCs<>|j}|j}d|kr[t|jj<00>}t|<00>}|j|jkr[|d=q[n|jrpt|<00>nd}|dk r<>|j|<00>ndS(s<>
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.
t AuthorizationN( RIRLRtrequestthostnamet trust_envRR!t prepare_auth(R^RbR.RIRLtoriginal_parsedtredirect_parsedtnew_auth((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR\<00>s      c Cs|j}|j}t|<00>j}|dk r9|j<00>ni}|jr<>t|<00> r<>t|<00>}|j |<00>}|r<>|j
|||<19>q<>nd|kr<>|d=nyt ||<19>\} }
Wnt k
r<>d\} }
nX| r|
rt | |
<00>|d<n|S(s<>
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.
sProxy-AuthorizationN(NN(RIRLRRMR!RARiRRR/t
setdefaultRRWR( R^RbR>RIRLRMt new_proxiestenviron_proxiestproxytusernametpassword((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR[<00>s$    
  N(t__name__t
__module__RFR!tTrueReR\R[(((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR3Xsa tSessioncBseZdZddddddddd d
d d d dgZd<00>Zd<00>Zd<00>Zd<00>Zd!d!d!d!d!d!d!e d!d!d!d!d!d<00> Z
d<00>Z d<00>Z d<00>Z d!d<00>Zd!d<00>Zd!d<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd <00>ZRS("s<>A Requests session.
Provides cookie persistence, connection-pooling, and configuration.
Basic Usage::
>>> import requests
>>> s = requests.Session()
>>> s.get('http://httpbin.org/get')
200
RIRYtauthR;R>thookstparamsR<R=tprefetchtadaptersR:RiRGcCs<>t<00>|_d|_i|_t<00>|_i|_t|_ t
|_ d|_ t |_t
|_ti<00>|_t<00>|_|jdt<00><00>|jdt<00><00>dS(Nshttps://shttp://(RRIR!RxR>RRyRzRFR:RvR<R=RRGRiRRYRR|tmountR(R^((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt__init__ s           cCs|S(N((R^((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt __enter__?scGs|j<00>dS(N(RH(R^targs((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt__exit__BscCs!|jp i}t|tj<00>s0t|<00>}nttt<00>|j<00>|<00>}|j}|jr<>| r<>|j r<>t |j
<00>}nt <00>}|j d|j j<00>d|j
d|jd|jdt|j|jdt<00>dt|j|j<00>dt||j<00>d |d
t|j|j<00><00> |S( sbConstructs 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.
RJRLtfilestdataRIR+RzRxRYRy(RYR%Rt CookieJarRR R
RxRiRRLR tprepareRJtupperR<72>R<>R-RIRRzR2Ry(R^RgRYtmerged_cookiesRxtp((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytprepare_requestEs(       cCs<>t|<00>}td|j<00>d|d|d|d|p9id|pEid|d|d | <00> }|j|<00>}| pui} |jrt|<00>p<>i}x*|j<00>D]\}}| j||<00>q<>W| r<>|tk r<>t j
j d
<00>}n| r|tk rt j
j d <00>}qnt | |j <00>} t | |j<00>} t ||j<00>}t ||j<00>}i| d 6| d 6|d6|d6| d6|
d6}|j||<00>}|S(s4Constructs 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 or bytes 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) Float describing the timeout of the
request in seconds.
:param allow_redirects: (optional) Boolean. Set to True by default.
:param proxies: (optional) Dictionary mapping protocol to the URL of
the proxy.
:param stream: (optional) whether to immediately download the response
content. Defaults to ``False``.
:param verify: (optional) if ``True``, the SSL cert will be verified.
A CA_BUNDLE path can also be provided.
:param cert: (optional) if String, path to ssl client cert file (.pem).
If Tuple, ('cert', 'key') pair.
RJRLRIR<>R<>RzRxRYRytREQUESTS_CA_BUNDLEtCURL_CA_BUNDLER:R;R<R=R>R?(RR R<>R<>RiRR'RnRFtostenvironR/R-R>R:R<R=R](R^RJRLRzR<>RIRYR<>RxR;R?R>RyR:R<R=R`tprept env_proxiesR#R$t send_kwargsR_((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyRglsD,       
cKs#|jdt<00>|jd||<00>S(s<>Sends a GET request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
R?R7(RnRvRg(R^RLtkwargs((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR/<00>scKs#|jdt<00>|jd||<00>S(s<>Sends a OPTIONS request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
R?tOPTIONS(RnRvRg(R^RLR<>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytoptions<6E>scKs#|jdt<00>|jd||<00>S(s<>Sends a HEAD request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
R?R6(RnRFRg(R^RLR<>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pythead<61>scKs|jd|d||<00>S(s8Sends a POST request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
R8R<>(Rg(R^RLR<>R<>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytpost<73>scKs|jd|d||<00>S(s7Sends a PUT request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
tPUTR<54>(Rg(R^RLR<>R<>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytput<75>scKs|jd|d||<00>S(s9Sends a PATCH request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
tPATCHR<48>(Rg(R^RLR<>R<>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytpatch<63>scKs|jd||<00>S(s<>Sends a DELETE request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
tDELETE(Rg(R^RLR<>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytdeletesc Ks|jd|j<00>|jd|j<00>|jd|j<00>|jd|j<00>t|t<00>sjtd<00><00>n|jdt <00>}|j
d<00>}|j
d<00>}|j
d<00>}|j
d<00>}|j
d<00>}|j } |j d|j <00>}
tj<00>} |
j||<00>} tj<00>| | _td | | |<00>} | jrdx-| jD]} t|j| j| j<00>q>Wnt|j|| j<00>|j| |d|d|d|d|d|<00>}|r<>g|D]} | ^q<>ng}|r<>|jd
| <00>|j<00>} || _n|s | jn| S( sSend a given PreparedRequest.R:R<R=R>s#You can only send PreparedRequests.R?R;RLR.i(RnR:R<R=R>R%R t
ValueErrortpopRvR/Ryt get_adapterRLRtutcnowR]telapsedRthistoryR RYRgRDRetinsertRB(R^RgR<>R?R:R;R<R=R>RytadaptertstarttrR_tgenR<6E>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR]sH     %  
cCsMx6|jj<00>D]%\}}|j<00>j|<00>r|SqWtd|<16><00>dS(s>Returns the appropriate connnection adapter for the given URL.s*No connection adapters were found for '%s'N(R|R'tlowerRKR(R^RLtprefixR<78>((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR<79>XscCs(x!|jj<00>D]}|j<00>qWdS(s+Closes all adapters and as such the sessionN(R|tvaluesRH(R^R$((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyRHbscCso||j|<g|jD]$}t|<00>t|<00>kr|^q}x'|D]}|jj|<00>|j|<qHWdS(skRegisters a connection adapter to a prefix.
Adapters are sorted in descending order by key length.N(R|tlenR<6E>(R^R<>R<>R#t keys_to_movetkey((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyR}gs 4 cst<00>fd<00><00>jD<><00>S(Nc3s'|]}|t<00>|d<00>fVqdS(N(tgetattrR!(R"tattr(R^(sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pys <genexpr>ss(R(t __attrs__(R^((R^sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt __getstate__rscCs1x*|j<00>D]\}}t|||<00>q WdS(N(R'tsetattr(R^tstateR<65>tvalue((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt __setstate__usN(RtRut__doc__R<5F>R~RR<>R<>R!RvRgR/R<>R<>R<>R<>R<>R<>R]R<>RHR}R<>R<>(((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyRw<00>sD   3   ( S
G
 cCst<00>S(s2Returns a :class:`Session` for context-management.(Rw(((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pytsessionzs(4R<>R<>t collectionsRRRxRtcompatRRRRRRYRR R
R tmodelsR R RRyRRtutilsRRRt
exceptionsRRRRt
structuresRR|RRRRRRt status_codesRR R-R2tobjectR3RwR<>(((sSc:\users\lifqian\appdata\local\temp\pip_build_lifqian\requests\requests\sessions.pyt<module>
s* (""( ! <16><16><00>