Viewing File: /usr/lib/python2.7/site-packages/requests/sessions.pyo

ó
ZÐ…_c@sËdZddlZddlmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
mZmZmZdd	lmZmZmZdd
lmZmZddlmZmZmZmZddlmZmZm Z m!Z!dd
l"m#Z#ddl$m%Z%ddl&m'Z'ddlm(Z(m)Z)m*Z*m+Z+m,Z,ddl-m.Z.ddlm/Z/dZ0e	d„Z1e	d„Z2de3fd„ƒYZ4de4fd„ƒYZ5d„Z6dS(s”
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).

iÿÿÿÿN(tMapping(tdatetimei(t_basic_auth_str(t	cookielibtOrderedDictturljointurlparse(tcookiejar_from_dicttextract_cookies_to_jartRequestsCookieJart
merge_cookies(tRequesttPreparedRequesttDEFAULT_REDIRECT_LIMIT(t
default_hookst
dispatch_hook(tto_key_val_listtdefault_headerstto_native_stringt
DEFAULT_PORTS(tTooManyRedirectst
InvalidSchematChunkedEncodingErrortContentDecodingError(tRecentlyUsedContainer(tCaseInsensitiveDict(tHTTPAdapter(trequote_uritget_environ_proxiestget_netrc_authtshould_bypass_proxiestget_auth_from_url(tcodes(tREDIRECT_STATIiècCsº|dkr|S|dkr |St|tƒo;t|tƒsB|S|t|ƒƒ}|jt|ƒƒx0|jƒD]"\}}|dkrt||=qtqtWtd„|jƒDƒƒ}|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((s5/usr/lib/python2.7/site-packages/requests/sessions.pys	<genexpr>FsN(R"t
isinstanceRRtupdatetitemstdict(trequest_settingtsession_settingt
dict_classtmerged_settingR$R%((s5/usr/lib/python2.7/site-packages/requests/sessions.pyt
merge_setting*scCsZ|dks!|jdƒgkr%|S|dksF|jdƒgkrJ|St|||ƒ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,((s5/usr/lib/python2.7/site-packages/requests/sessions.pytmerge_hooksKs
!!tSessionRedirectMixincBs;eZd„Zededdd„Zd„Zd„ZRS(cCsàt|ƒ}t|ƒ}|j|jkr.tS|jdkrn|jdkrn|jdkrn|jdkrntS|j|jk}|j|jk}tj|jdƒdf}|rÖ|j|krÖ|j|krÖtS|pß|S(sFDecide whether Authorization header should be removed when redirectingthttpiPthttpsi»N(iPN(i»N(	RthostnametTruetschemetportR"tFalseRR0(tselftold_urltnew_urlt
old_parsedt
new_parsedtchanged_porttchanged_schemetdefault_port((s5/usr/lib/python2.7/site-packages/requests/sessions.pytshould_strip_auth]sccs;d}g}	x(|jr6|jƒ}
|dkrU|	j|ƒt|	ƒ}||_ny|jWn-tttfk
r|j	j
dtƒnX||jkrµt
d|jƒ‚n|jƒ|jd}|j}
|jdƒr	t|jƒ}d|j|f}nt|ƒ}|jƒ}|jsEt|jt|ƒƒ}nt|ƒ}t|ƒ|
_|jr‘|j|
jkr‘|
j|j|j<n|jtjkr¸|
dkr¸d}
n|jtjkrß|
dkrßd}
n|jtj kr|
d	krd}
n|
|
_|jtj!tj"fkrRd
|
jkrF|
jd
=nd|
_$n|
j}y|d=Wnt%k
rynXt&|
j'||j	ƒ|
j'j(|j)ƒ|
j*|
j'ƒ|j+|
|ƒ}|j,|
|ƒ|
}|j-|d|d
|d|d|d|dtƒ}t&|j)|
|j	ƒ|d7}|VqWdS(s6Receives a Response. Returns a generator of Responses.itdecode_contentsExceeded %s redirects.tlocations//s%s:%stHEADtGETtPOSTsContent-LengthtCookietstreamttimeouttverifytcerttproxiestallow_redirectsiN(.tis_redirecttcopytappendtlistthistorytcontentRRtRuntimeErrortrawtreadR;t
max_redirectsRtclosetheaderstmethodt
startswithRturlR9tgeturltnetlocRRRtis_permanent_redirecttredirect_cachetstatus_codeR t	see_othertfoundtmovedttemporary_redirecttpermanent_redirectR"tbodytKeyErrorRt_cookiesR'tcookiestprepare_cookiestrebuild_proxiestrebuild_authtsend(R<tresptreqRKRLRMRNROtithisttprepared_requesttnew_histR_R]tparsed_rurltparsedR\((s5/usr/lib/python2.7/site-packages/requests/sessions.pytresolve_redirectsvs|


						
	
	
cCs{|j}|j}d|kr@|j|jj|ƒr@|d=n|jrUt|ƒnd}|dk	rw|j|ƒ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(R\R_RDtrequestt	trust_envRR"tprepare_auth(R<RvR/R\R_tnew_auth((s5/usr/lib/python2.7/site-packages/requests/sessions.pyRpås		$
cCs|j}|j}t|ƒj}|dk	r9|jƒni}|jrt|ƒrt|ƒ}|j	|ƒ}|r|j
|||ƒqnd|kr¦|d=nyt||ƒ\}	}
Wntk
rßd\}	}
nX|	r|
rt
|	|
ƒ|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(R\R_RR9R"RRR}RRR0t
setdefaultRRkR(R<RvROR\R_R9tnew_proxiestenviron_proxiestproxytusernametpassword((s5/usr/lib/python2.7/site-packages/requests/sessions.pyRoús$		

N(	t__name__t
__module__RDR;R"R8RzRpRo(((s5/usr/lib/python2.7/site-packages/requests/sessions.pyR4[s
	n	tSessioncBseZdZddddddddd	d
ddd
g
Zd„Zd„Zd„Zd„Zd!d!d!d!d!d!d!e	d!d!d!d!d!d!d„Z
d„Zd„Zd„Z
d!d!d„Zd!d„Zd!d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd „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
    R\RmtauthROthookstparamsRMRNtprefetchtadaptersRKR}RZcCs´tƒ|_d|_i|_tƒ|_i|_t|_	t
|_d|_t
|_t
|_tiƒ|_tƒ|_|jdtƒƒ|jdtƒƒttƒ|_dS(Nshttps://shttp://(RR\R"R‰RORRŠR‹R;RKR8RMRNR
RZR}RRmRRtmountRRtREDIRECT_CACHE_SIZERc(R<((s5/usr/lib/python2.7/site-packages/requests/sessions.pyt__init__3s								cCs|S(N((R<((s5/usr/lib/python2.7/site-packages/requests/sessions.pyt	__enter__iscGs|jƒdS(N(R[(R<targs((s5/usr/lib/python2.7/site-packages/requests/sessions.pyt__exit__lscCs*|jpi}t|tjƒs0t|ƒ}ntttƒ|jƒ|ƒ}|j}|jrƒ|rƒ|jrƒt	|j
ƒ}ntƒ}|jd|j
jƒd|j
d|jd|jd|jdt|j|jdtƒdt|j|jƒd	t||jƒd
|dt|j|jƒƒ
|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.
        R]R_tfilestdatatjsonR\R,R‹R‰RmRŠ(RmR&Rt	CookieJarRR
R	R‰R}RR_RtprepareR]tupperR”R•R–R.R\RR‹R3RŠ(R<R|Rmtmerged_cookiesR‰tp((s5/usr/lib/python2.7/site-packages/requests/sessions.pytprepare_requestos*								cCsÓt|ƒ}td|jƒd|d|d|d|p9id|d|pKid|d	|d
|ƒ
}|j|ƒ}|p{i}|j|j||
||ƒ}i|	d6|
d6}|j|ƒ|j||}|S(
sCConstructs 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 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 (`connect timeout, read
            timeout <user/advanced.html#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 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.
        R]R_R\R”R•R–R‹R‰RmRŠRLRP(RRR™Rœtmerge_environment_settingsR_R'Rq(R<R]R_R‹R•R\RmR”R‰RLRPRORŠRKRMRNR–Rstpreptsettingstsend_kwargsRr((s5/usr/lib/python2.7/site-packages/requests/sessions.pyR|—s,2	

cKs#|jdtƒ|jd||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.
        RPRH(R€R8R|(R<R_tkwargs((s5/usr/lib/python2.7/site-packages/requests/sessions.pyR0êscKs#|jdtƒ|jd||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.
        RPtOPTIONS(R€R8R|(R<R_R¡((s5/usr/lib/python2.7/site-packages/requests/sessions.pytoptionsôscKs#|jdtƒ|jd||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.
        RPRG(R€R;R|(R<R_R¡((s5/usr/lib/python2.7/site-packages/requests/sessions.pytheadþscKs|jd|d|d||S(sŠSends 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 json: (optional) json to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        RIR•R–(R|(R<R_R•R–R¡((s5/usr/lib/python2.7/site-packages/requests/sessions.pytposts	cKs|jd|d||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•(R|(R<R_R•R¡((s5/usr/lib/python2.7/site-packages/requests/sessions.pytputscKs|jd|d||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•(R|(R<R_R•R¡((s5/usr/lib/python2.7/site-packages/requests/sessions.pytpatchscKs|jd||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(R|(R<R_R¡((s5/usr/lib/python2.7/site-packages/requests/sessions.pytdelete'sc
Ksq|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒt|tƒsjtdƒ‚ntƒ}xT|j	|j
krÉ|j|j	ƒ|j
j|j	ƒ}||kr½Pn||_	qvW|j
dtƒ}|jdƒ}|jdƒ}|jdƒ}|jdƒ}	|jdƒ}
|j}|jd|j	ƒ}tjƒ}
|j||}tjƒ|
|_td	|||}|jrÄx-|jD]}t|j|j|jƒqžWnt|j||jƒ|j||d|d|d|d|	d|
ƒ}|r)g|D]}|^qng}|r]|jd
|ƒ|j
ƒ}||_n|sm|jn|S(sSend a given PreparedRequest.RKRMRNROs#You can only send PreparedRequests.RPRLR_R/i(R€RKRMRNROR&Rt
ValueErrortsetR_RctaddR0tpopR8RŠtget_adapterRtutcnowRqtelapsedRRURRmR|RXRztinsertRV(R<R|R¡tchecked_urlsR>RPRKRLRMRNRORŠtadaptertstarttrRrtgenRU((s5/usr/lib/python2.7/site-packages/requests/sessions.pyRq0sV	
		 	%
c	Csò|jrŠt|ƒpi}x*|jƒD]\}}|j||ƒq(W|tks`|dkrŠtjjdƒptjjdƒ}qŠnt	||j
ƒ}t	||jƒ}t	||jƒ}t	||j
ƒ}i|d6|d6|d6|d6S(s6Check the environment and merge it with some settings.tREQUESTS_CA_BUNDLEtCURL_CA_BUNDLERMRORKRNN(R}RR(R€R8R"tostenvironR0R.RORKRMRN(	R<R_RORKRMRNtenv_proxiesR$R%((s5/usr/lib/python2.7/site-packages/requests/sessions.pyRs	cCsMx6|jjƒD]%\}}|jƒj|ƒr|SqWtd|ƒ‚dS(s>Returns the appropriate connnection adapter for the given URL.s*No connection adapters were found for '%s'N(RR(tlowerR^R(R<R_tprefixRµ((s5/usr/lib/python2.7/site-packages/requests/sessions.pyR°—scCs(x!|jjƒD]}|jƒqWdS(s+Closes all adapters and as such the sessionN(RtvaluesR[(R<R%((s5/usr/lib/python2.7/site-packages/requests/sessions.pyR[¡scCso||j|<g|jD]$}t|ƒt|ƒkr|^q}x'|D]}|jj|ƒ|j|<qHWdS(skRegisters a connection adapter to a prefix.

        Adapters are sorted in descending order by key length.N(RtlenR¯(R<R¿RµR$tkeys_to_movetkey((s5/usr/lib/python2.7/site-packages/requests/sessions.pyRަs
4
cs6t‡fd†ˆjDƒƒ}tˆjƒ|d<|S(Nc3s'|]}|tˆ|dƒfVqdS(N(tgetattrR"(R#tattr(R<(s5/usr/lib/python2.7/site-packages/requests/sessions.pys	<genexpr>²sRc(R)t	__attrs__Rc(R<tstate((R<s5/usr/lib/python2.7/site-packages/requests/sessions.pyt__getstate__±scCs||jdiƒ}x*|jƒD]\}}t|||ƒqWttƒ|_x'|jƒD]\}}||j|<q[WdS(NRc(R¯R(tsetattrRRRc(R<RÇRcRÅtvaluetredirecttto((s5/usr/lib/python2.7/site-packages/requests/sessions.pyt__setstate__¶sN(R†R‡t__doc__RÆRR‘R“RœR"R8R|R0R£R¤R¥R§R©R«RqRR°R[RŽRÈRÍ(((s5/usr/lib/python2.7/site-packages/requests/sessions.pyRˆ sH		6			)E	
	
	


			O		
			cCstƒS(s2Returns a :class:`Session` for context-management.(Rˆ(((s5/usr/lib/python2.7/site-packages/requests/sessions.pytsessionÀs(7RÎR»tcollectionsRRR‰RtcompatRRRRRmRRR	R
tmodelsRRR
RŠRRtutilsRRRRt
exceptionsRRRRturllib3._collectionsRt
structuresRRRRRRRRtstatus_codesR R!RR.R3tobjectR4RˆRÏ(((s5/usr/lib/python2.7/site-packages/requests/sessions.pyt<module>
s.""""(!Åÿ¡
Back to Directory File Manager