U C^'@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd Zd d ZGd ddeZGdddeZGdddeZGdddeZdS)z] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. N) b64encode)urlparsestr basestring)extract_cookies_to_jar)to_native_string)parse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datacCst|ts&tjd|tdt|}t|tsLtjd|tdt|}t|tr`|d}t|trt|d}dtt 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 :) isinstancerwarningswarnformatDeprecationWarningrencoderrjoinstrip)usernamepasswordauthstrr3/tmp/pip-install-6_kvzl1k/requests/requests/auth.py_basic_auth_strs0      rc@seZdZdZddZdS)AuthBasez4Base class that all auth implementations derive fromcCs tddS)NzAuth hooks must be callable.)NotImplementedErrorselfrrrr__call__KszAuthBase.__call__N__name__ __module__ __qualname____doc__r rrrrrHsrc@s0eZdZdZddZddZddZdd Zd S) HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dSN)rrrrrrrr__init__RszHTTPBasicAuth.__init__cCs(t|jt|ddk|jt|ddkgSNrrallrgetattrrrotherrrr__eq__VszHTTPBasicAuth.__eq__cCs ||k Sr'rr.rrr__ne__\szHTTPBasicAuth.__ne__cCst|j|j|jd<|S)N Authorizationrrrheadersrrrrr _szHTTPBasicAuth.__call__N)r"r#r$r%r)r0r1r rrrrr&Os r&c@seZdZdZddZdS) HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|j|jd<|S)NzProxy-Authorizationr3rrrrr gszHTTPProxyAuth.__call__Nr!rrrrr5dsr5c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.cCs||_||_t|_dSr')rr threadinglocal _thread_localr(rrrr)oszHTTPDigestAuth.__init__cCs@t|jds.md5_utf8SHAcSs"t|tr|d}t|SrI)r rrrKsha1rMrNrrrsha_utf8s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|tr|d}t|SrI)r rrrKsha256rMrNrrr sha256_utf8s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|tr|d}t|SrI)r rrrKsha512rMrNrrr sha512_utf8s  z7HTTPDigestAuth.build_digest_header..sha512_utf8csd||fS)N%s:%sr)sd hash_utf8rrz4HTTPDigestAuth.build_digest_header../?z%s:%s:%srXrz%08xrJauth,z%s:%s:%s:%s:%sz>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z , opaque="%s"z, algorithm="%s"z , digest="%s"z , qop="auth", nc=%s, cnonce="%s"z Digest %s)r9r?getupperrpathqueryrrr=r>rrtimectimeosurandomrKrRrMsplit)rmethodurlrCrDrErFrG _algorithmrPrSrUrWKDentdigp_parsedrgA1A2HA1HA2ncvaluerYcnoncerespdignoncebitbaserr[rbuild_digest_headers           z"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN) is_redirectr9rA)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-authenticater;digestzdigest )flags)countr2) status_coder9rAr@requestbodyseekr4relowerrecompile IGNORECASEr subr?contentclosecopyr_cookiesrawprepare_cookiesr}rnro connectionsendhistoryappend)rrrs_authpatprep_rrrr handle_401s2      zHTTPDigestAuth.handle_401cCs~||jjr&||j|j|jd<z|j|j_ Wnt k rTd|j_ YnX| d|j | d|j d|j_|S)Nr2responser)rBr9r=r}rnror4rtellr@AttributeError register_hookrrrArrrrr szHTTPDigestAuth.__call__cCs(t|jt|ddk|jt|ddkgSr*r+r.rrrr0*szHTTPDigestAuth.__eq__cCs ||k Sr'rr.rrrr10szHTTPDigestAuth.__ne__N) r"r#r$r%r)rBr}rrr r0r1rrrrr6ls f,r6)r%rkrrirKr7rbase64rcompatrrrcookiesr_internal_utilsrutilsr CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTrobjectrr&r5r6rrrrs$    ,