B /Wb'@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZddlmZddlmZd Zd Zd d ZGd ddZGdddeZGdddeZGdddeZdS)z] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. N) b64encode)to_native_string) basestringstrurlparse)extract_cookies_to_jar)parse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datacCst|ts&tjd|tdt|}t|tsPtjdt|tdt|}t|trd|d}t|trx|d}dt t d ||f }|S)zReturns a Basic Auth string.zNon-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({!r}) to a string or bytes object in the near future to avoid problems.)categoryzNon-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({!r}) to a string or bytes object in the near future to avoid problems.latin1zBasic :) isinstancerwarningswarnformatDeprecationWarningrtypeencoderrjoinstrip)usernamepasswordauthstrr4/tmp/pip-target-ju3w756n/lib/python/requests/auth.py_basic_auth_strs&      rc@seZdZdZddZdS)AuthBasez4Base class that all auth implementations derive fromcCs tddS)NzAuth hooks must be callable.)NotImplementedError)selfrrrr__call__HszAuthBase.__call__N)__name__ __module__ __qualname____doc__r rrrrrEsrc@s0eZdZdZddZddZddZdd Zd S) HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS)N)rr)rrrrrr__init__OszHTTPBasicAuth.__init__cCs(t|jt|ddk|jt|ddkgS)Nrr)allrgetattrr)rotherrrr__eq__SszHTTPBasicAuth.__eq__cCs ||k S)Nr)rr)rrr__ne__[szHTTPBasicAuth.__ne__cCst|j|j|jd<|S)N Authorization)rrrheaders)rrrrrr ^szHTTPBasicAuth.__call__N)r!r"r#r$r&r*r+r rrrrr%Ls r%c@seZdZdZddZdS) HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|j|jd<|S)NzProxy-Authorization)rrrr-)rrrrrr fszHTTPProxyAuth.__call__N)r!r"r#r$r rrrrr.csr.c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.cCs||_||_t|_dS)N)rr threadinglocal _thread_local)rrrrrrr&nszHTTPDigestAuth.__init__cCs@t|jds.md5_utf8SHAcSs"t|tr|d}t|S)Nzutf-8)r rrrBsha1rD)rErrrsha_utf8s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|tr|d}t|S)Nzutf-8)r rrrBsha256rD)rErrr sha256_utf8s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|tr|d}t|S)Nzutf-8)r rrrBsha512rD)rErrr sha512_utf8s  z7HTTPDigestAuth.build_digest_header..sha512_utf8cs|d|S)N:r)sd) hash_utf8rrz4HTTPDigestAuth.build_digest_header../?rNrZ08xzutf-8auth,z:auth:z username="z ", realm="z ", nonce="z", uri="z ", response=""z , opaque="z , algorithm="z , digest="z, qop="auth", nc=z , cnonce="zDigest )r2r8getupperrpathqueryrrr6r7rrtimectimeosurandomrBrHrDsplit)rmethodurlr<r=r>r?r@ _algorithmrFrIrKrMKDentdigp_parsedr]A1A2HA1HA2ncvaluerOcnoncerespdignoncebitbaser)rQrbuild_digest_header~sz       &z"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN) is_redirectr2r:)rrkwargsrrrhandle_redirectszHTTPDigestAuth.handle_redirectcKs"d|jkrdks$nd|j_|S|jjdk rB|jj|jj|jdd}d| kr|jjdkr|jjd7_t j d t j d }t |jd|dd |j_|j||j}t|j|j|j||j||j|j|jd <|jj|f|}|j|||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response iirNzwww-authenticater4digestzdigest )flags)countr,) status_coder2r:r9requestbodyseekr-r[lowerrecompile IGNORECASEr subr8contentclosecopyr_cookiesrawprepare_cookiesrsrdre connectionsendhistoryappend)rrrus_authpatprep_rrrr handle_401s.     zHTTPDigestAuth.handle_401cCs~||jjr&||j|j|jd<y|j|j_ Wnt k rTd|j_ YnX| d|j | d|j d|j_|S)Nr,responser)r;r2r6rsrdrer-r}tellr9AttributeError register_hookrrvr:)rrrrrr szHTTPDigestAuth.__call__cCs(t|jt|ddk|jt|ddkgS)Nrr)r'rr(r)rr)rrrr*2szHTTPDigestAuth.__eq__cCs ||k S)Nr)rr)rrrr+:szHTTPDigestAuth.__ne__N) r!r"r#r$r&r;rsrvrr r*r+rrrrr/ks n-r/)r$rBrarr0r_rbase64r_internal_utilsrcompatrrrcookiesrutilsr CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTrrr%r.r/rrrrs$    ,