ó b@RTc@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„Z.e d„Z/de0fd„ƒYZ1de1fd„ƒYZ2d„Z3dS(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 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ƒ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((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pys CsN(R!t isinstanceRRtupdatetitemstdict(trequest_settingtsession_settingt dict_classtmerged_settingR#R$((s>/opt/freeware/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+((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt merge_hooksHs !!tSessionRedirectMixincBs2eZededdd„Zd„Zd„ZRS(ccsAd}g} x.|jr<|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ƒ} t| ƒjsKt|jt| ƒƒ} n t| ƒ} t| ƒ| _|jr—|j| jkr—| j|j|jtithisttprepared_requesttnew_histRORMt parsed_rurltparsedRL((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pytresolve_redirectsYs|                         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(RcRhR.RLROtoriginal_parsedtredirect_parsedtnew_auth((s>/opt/freeware/lib/python2.7/site-packages/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((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyR`Þs$       N(t__name__t __module__RIR!tTrueRlRaR`(((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyR3Xsk tSessioncBseZdZddddddddd d d d d dgZd„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:RpRJRTcCs®tƒ|_d|_i|_tƒ|_i|_t|_ t |_ d|_ t |_t |_tiƒ|_tƒ|_|jdtƒƒ|jdtƒƒi|_dS(Nshttps://shttp://(RRLR!RR>RR€RRIR:R}R<R=RRJRpRR^RRƒtmountRRT(Rc((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt__init__s           cCs|S(N((Rc((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt __enter__LscGs|jƒdS(N(RK(Rctargs((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt__exit__OscCs*|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+RRR^R€(R^R%Rt CookieJarRR R RRpRROR tprepareRMtupperR‰RŠR‹R-RLRRR2R€(RcRnR^tmerged_cookiesRtp((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pytprepare_requestRs*        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ŠR‹RRR^R€R;R?(RR RŽR‘tmerge_environment_settingsROR&Rb(RcRMRORRŠRLR^R‰RR;R?R>R€R:R<R=R‹Retpreptsettingst send_kwargsRd((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyRnzs,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(RuR}Rn(RcROtkwargs((s>/opt/freeware/lib/python2.7/site-packages/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(RuR}Rn(RcROR–((s>/opt/freeware/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. R?R6(RuRIRn(RcROR–((s>/opt/freeware/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. R8RŠR‹(Rn(RcRORŠR‹R–((s>/opt/freeware/lib/python2.7/site-packages/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Š(Rn(RcRORŠR–((s>/opt/freeware/lib/python2.7/site-packages/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Š(Rn(RcRORŠR–((s>/opt/freeware/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(Rn(RcROR–((s>/opt/freeware/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.R:R<R=R>s#You can only send PreparedRequests.R?R;ROR.i(RuR:R<R=R>R%R t ValueErrortsetRORTtaddR/tpopR}R€t get_adapterRtutcnowRbtelapsedRRDR R^RnRGRltinsertRE(RcRnR–t checked_urlstnew_urlR?R:R;R<R=R>R€tadaptertstarttrRdtgenRD((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyRbsV        %   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(RpRR'RuR}R!tostenvironR/R-R>R:R<R=( RcROR>R:R<R=t env_proxiesR#R$((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyR’bs 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«((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyR¥zscCs(x!|jjƒD]}|jƒqWdS(s+Closes all adapters and as such the sessionN(RƒtvaluesRK(RcR$((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyRK„scCso||j|/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyR„‰s 4 cst‡fd†ˆjDƒƒS(Nc3s'|]}|tˆ|dƒfVqdS(N(tgetattrR!(R"tattr(Rc(s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pys •s(R(t __attrs__(Rc((Rcs>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt __getstate__”scCs1x*|jƒD]\}}t|||ƒq WdS(N(R'tsetattr(RctstateR»tvalue((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt __setstate__—sN(R{R|t__doc__R¼R…R†RˆR‘R!R}RnR/R˜R™RšRœRžR RbR’R¥RKR„R½RÁ(((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyR~sH   5   ) E  O   cCstƒS(s2Returns a :class:`Session` for context-management.(R~(((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pytsessionœs(4RÂR±t collectionsRRRRtcompatRRRRRR^RR R R tmodelsR R RR€RRtutilsRRRt exceptionsRRRRt structuresRRƒRRRRRRt status_codesRR R-R2tobjectR3R~RÃ(((s>/opt/freeware/lib/python2.7/site-packages/requests/sessions.pyt s* (""( ! ¬ÿ™