ó –ee[c@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|ƒƒ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((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pys FsN(R!t isinstanceRRtupdatetitemstdict(trequest_settingtsession_settingt dict_classtmerged_settingR#R$((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/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+((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyt merge_hooksKs !!tSessionRedirectMixincBs2eZededdd„Zd„Zd„ZRS(cks>d} g} x+|jr9|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|jtadapter_kwargstithisttprepared_requesttnew_histRORMt parsed_rurltparsedRL((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pytresolve_redirects\s~                          cCs–|j}|j}d|kr[t|jjƒ}t|ƒ}|j|jkr[|d=q[n|jrpt|ƒnd}|dk r’|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( RLRORtrequestthostnamet trust_envRR!t prepare_auth(RcRiR.RLROtoriginal_parsedtredirect_parsedtnew_auth((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyRaÌs      c Cs|j}|j}t|ƒj}|dk r9|jƒni}|jrt|ƒ rt|ƒ}|j |ƒ}|r|j |||ƒqnd|kr¦|d=nyt ||ƒ\} } Wnt k rßd\} } nX| r| rt | | ƒ|dRLRORPt new_proxiestenviron_proxiestproxytusernametpassword((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyR`ås$       N(t__name__t __module__RIR!tTrueRmRaR`(((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyR3[so 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') 200 RLR^tauthR>thookstparamsR<R=tprefetchtadaptersR:RqRJcCs´tƒ|_d|_i|_tƒ|_i|_t|_ t |_ d|_ t |_t |_tiƒ|_tƒ|_|jdtƒƒ|jdtƒƒttƒ|_dS(Nshttps://shttp://(RRLR!R€R>RRR‚RIR:R~R<R=R RJRqRR^RR„tmountRRtREDIRECT_CACHE_SIZERT(Rc((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyt__init__s           cCs|S(N((Rc((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyt __enter__TscGs|jƒdS(N(RK(Rctargs((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyt__exit__WscCs*|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( sbConstructs 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. RMROtfilestdatatjsonRLR+R‚R€R^R(R^R%Rt CookieJarRR R R€RqRROR tprepareRMtupperR‹RŒRR-RLRR‚R2R(RcRoR^tmerged_cookiesR€tp((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pytprepare_requestZs*        cCsÓt|ƒ}td|jƒd|d|d|d|p9id|d|pKid|d |d | ƒ }|j|ƒ}| p{i} |j|j| | ||ƒ}i| d 6| d 6}|j|ƒ|j||}|S( sCConstructs 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 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 `_) 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. RMRORLR‹RŒRR‚R€R^RR;R?(RR RR“tmerge_environment_settingsROR&Rb(RcRMROR‚RŒRLR^R‹R€R;R?R>RR:R<R=RRetpreptsettingst send_kwargsRd((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyRo‚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. R?R7(RvR~Ro(RcROtkwargs((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/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. R?tOPTIONS(RvR~Ro(RcROR˜((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/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. R?R6(RvRIRo(RcROR˜((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/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. R8RŒR(Ro(RcRORŒRR˜((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pytpostós 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Œ(Ro(RcRORŒR˜((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pytputþscKs|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Œ(Ro(RcRORŒR˜((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/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(Ro(RcROR˜((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pytdeletescKs|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}|jd|j ƒ}tjƒ} |j||} tjƒ| | _td|| |} | jrˆx-| jD]} t|j| j| jƒqbWnt|j|| jƒ|j| ||} |rÒg| D]} | ^qÀng} | r| jd | ƒ| j ƒ} | | _n|s| jn| S( sSend a given PreparedRequest.R:R<R=R>s#You can only send PreparedRequests.R?ROR.i(RvR:R<R=R>R%R t ValueErrortsetRORTtaddR/tpopR~Rt get_adapterRtutcnowRbtelapsedRRDRR^RoRGRmtinsertRE(RcRoR˜t checked_urlstnew_urlR?R:RtadaptertstarttrRdtgenRD((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyRbsD       %   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_BUNDLER<R>R:R=N(RqRR'RvR~R!tostenvironR/R-R>R:R<R=( RcROR>R:R<R=t env_proxiesR#R$((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyR”as 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(R„R'tlowerRNR(RcROtprefixR­((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyR§yscCs(x!|jjƒD]}|jƒqWdS(s+Closes all adapters and as such the sessionN(R„tvaluesRK(RcR$((sG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyRKƒscCso||j|”sRT(R(t __attrs__RT(Rctstate((RcsG/tmp/pip-install-xdEqop/botocore/botocore/vendored/requests/sessions.pyt __getstate__“scCs||jdiƒ}x*|jƒD]\}}t|||ƒqWttƒ|_x'|jƒD]\}}||j| s. """( ! °ÿ˜