ó `8(Zc@sÅdZddlZddlmZddlmZddlmZddlmZm Z m Z m Z ddl m Z mZmZmZdd lmZmZmZdd lmZmZdd lmZmZmZdd lmZmZmZm 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.dZ/e d„Z0e d„Z1de2fd„ƒYZ3de3fd„ƒYZ4d„Z5dS(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 cookielibt OrderedDictturljointurlparse(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(tRecentlyUsedContainer(tCaseInsensitiveDict(t HTTPAdapter(t requote_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|ƒƒg|jƒD]\}}|dkrt|^qt}x|D] }||=qŸW|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` N(tNonet isinstanceRRtupdatetitems(trequest_settingtsession_settingt dict_classtmerged_settingtktvt none_keystkey((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyt merge_setting)s  1  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'((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyt merge_hooksHs !!tSessionRedirectMixincBs;eZededdd„Zd„Zd„Zd„ZRS(cksÛd} g} xÈ|jrÖ|jƒ} | dkrU| j|ƒt| ƒ} | |_ny |jWn-tttfk r|j j dt ƒnX| |j kr»t d|j d|ƒ‚n|jƒ|jd} | jdƒrt|jƒ}d|j| f} nt| ƒ}|jƒ} |jsBt|jt| ƒƒ} n t| ƒ} t| ƒ| _|jrŽ|j| jkrŽ| j|j|jRnRRR/t setdefaultRRWR( R^RdR;RIRKRLt new_proxiestenviron_proxiestproxytusernametpassword((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyR[Ñs$       cCs‹|j}|jtjkr0|dkr0d}n|jtjkrW|dkrWd}n|jtjkr~|dkr~d}n||_dS(s‚When being redirected we may want to change the method of the request based on certain specs or browser behavior. tHEADtGETtPOSTN(tmethodRRRt see_othertfoundtmoved(R^RdR.R}((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyRQ÷s    N( t__name__t __module__RFR!tTrueRjR\R[RQ(((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyR3Ws `  &tSessioncBseZdZddddddddd d d d d g Zd„Zd„Zd„Zd„Zd!d!d!d!d!d!d!e d!d!d!d!d!d!d„Z d„Z d„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') Or as a context manager:: >>> with requests.Session() as s: >>> s.get('http://httpbin.org/get') RIRYtauthR;thookstparamsR9R:tprefetchtadaptersR7RnRGcCs´tƒ|_d|_i|_tƒ|_i|_t|_ t |_ d|_ t |_t |_tiƒ|_tƒ|_|jdtƒƒ|jdtƒƒttƒ|_dS(Nshttps://shttp://(RRIR!R…R;RR†R‡RFR7RƒR9R:R RGRnRRYRR‰tmountRRtREDIRECT_CACHE_SIZERP(R^((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyt__init__'s           cCs|S(N((R^((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyt __enter__`scGs|jƒdS(N(RH(R^targs((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyt__exit__cscCs*|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 |d t|j|jƒƒ |S( s‹Constructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest R}RKtfilestdatatjsonRIR'R‡R…RYR†(RYR"Rt CookieJarRR R R…RnRRKR tprepareR}tupperRR‘R’R-RIRR‡R2R†(R^RlRYtmerged_cookiesR…tp((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pytprepare_requestfs*        cCsÇtd|jƒd|d|d|d|p-id|d|p?id|d |d | ƒ }|j|ƒ}| poi} |j|j| | ||ƒ}i| d 6| d 6}|j|ƒ|j||}|S( s“Constructs a :class:`Request `, prepares it and sends it. Returns :class:`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, 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) ` 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) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to ``True``. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response R}RKRIRR‘R’R‡R…RYR†R8R<(R R•R˜tmerge_environment_settingsRKR#R](R^R}RKR‡R‘RIRYRR…R8R<R;R†R7R9R:R’R`tpreptsettingst send_kwargsR_((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyRlŽs*3       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. :rtype: requests.Response R<R{(RtRƒRl(R^RKtkwargs((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyR/ß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. :rtype: requests.Response R<tOPTIONS(RtRƒRl(R^RKR((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/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. :rtype: requests.Response R<Rz(RtRFRl(R^RKR((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/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. :rtype: requests.Response R|R‘R’(Rl(R^RKR‘R’R((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pytposts cKs|jd|d||S(sYSends 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. :rtype: requests.Response tPUTR‘(Rl(R^RKR‘R((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pytput s cKs|jd|d||S(s[Sends 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. :rtype: requests.Response tPATCHR‘(Rl(R^RKR‘R((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pytpatchs cKs|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. :rtype: requests.Response tDELETE(Rl(R^RKR((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pytdelete"scKs#|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒt|tƒrjtdƒ‚n|jdt ƒ}|j dƒ}|j }|rýt ƒ}xW|j |jkrù|j|j ƒ|jj |j ƒ}||kríPn||_ q¦Wn|jd|j ƒ}tjƒ} |j||} tjƒ| | _td|| |} | jr‘x-| jD]} t|j| j| jƒqkWnt|j|| jƒ|j| ||} |rÛg| D]} | ^qÉng} | r| jd | ƒ| jƒ} | | _n|s| jn| S( sR Send a given PreparedRequest. :rtype: requests.Response R7R9R:R;s#You can only send PreparedRequests.R<RKR.i(RtR7R9R:R;R"R t ValueErrorRURƒR/R†tsetRKRPtaddt get_adapterRtutcnowR]telapsedRRARRYRlRDRjtinsertRB(R^RlRR<R7R†t checked_urlstnew_urltadaptertstarttrR_tgenRA((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyR],sF      %   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(s^ Check the environment and merge it with some settings. :rtype: dict tREQUESTS_CA_BUNDLEtCURL_CA_BUNDLER9R;R7R:N(RnRR$RtRƒR!tostenvironR/R-R;R7R9R:( R^RKR;R7R9R:t env_proxiesR)R*((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyR™xs cCsMx6|jjƒD]%\}}|jƒj|ƒr|SqWtd|ƒ‚dS(s~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter s*No connection adapters were found for '%s'N(R‰R$tlowerRJR(R^RKtprefixR±((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyR«”scCs(x!|jjƒD]}|jƒqWdS(s+Closes all adapters and as such the sessionN(R‰tvaluesRH(R^R*((s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyRH¢scCso||j|³sRP(tdictt __attrs__RP(R^tstate((R^s:/tmp/pip-build-0nEYGB/pip/pip/_vendor/requests/sessions.pyt __getstate__²scCs||jdiƒ}x*|jƒD]\}}t|||ƒqWttƒ|_x'|jƒD]\}}||j| s. """(  ·ÿ´