3 _=\'@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&tjdj|tdt|}t|tsLtjdj|tdt|}t|tr`|jd}t|trt|jd}dtt dj ||fj }|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)usernamepasswordauthstrrg/private/var/folders/47/550316q90kl84vt_jn5ctz8chwmm0c/T/pip-install-yoigbb1v/requests/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__KszAuthBase.__call__N)__name__ __module__ __qualname____doc__rrrrrrHsrc@s0eZdZdZddZddZddZdd Zd S) HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS)N)rr)rrrrrr__init__RszHTTPBasicAuth.__init__cCs(t|jt|ddk|jt|ddkgS)Nrr)allrgetattrr)rotherrrr__eq__VszHTTPBasicAuth.__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*rrrrrr$Os r$c@seZdZdZddZdS) HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCst|j|j|jd<|S)NzProxy-Authorization)rrrr,)rrrrrrgszHTTPProxyAuth.__call__N)r r!r"r#rrrrrr-dsr-c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.cCs||_||_tj|_dS)N)rr threadinglocal _thread_local)rrrrrrr%oszHTTPDigestAuth.__init__cCs@t|jds.md5_utf8SHAcSs"t|tr|jd}tj|jS)Nzutf-8)r rrrAsha1rC)rDrrrsha_utf8s  z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSs"t|tr|jd}tj|jS)Nzutf-8)r rrrAsha256rC)rDrrr sha256_utf8s  z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSs"t|tr|jd}tj|jS)Nzutf-8)r rrrAsha512rC)rDrrr sha512_utf8s  z7HTTPDigestAuth.build_digest_header..sha512_utf8csd||fS)Nz%s:%sr)sd) hash_utf8rrsz4HTTPDigestAuth.build_digest_header../?z%s:%s:%sz%s:%srz%08xzutf-8auth,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)r1r7getupperrpathqueryrrr5r6rrtimectimeosurandomrArGrCsplit)rmethodurlr;r<r=r>r? _algorithmrErHrJrLKDentdigp_parsedrYA1A2HA1HA2ncvaluerMcnoncerespdignoncebitbaser)rOrbuild_digest_headers~           z"HTTPDigestAuth.build_digest_headercKs|jrd|j_dS)z)Reset num_401_calls counter on redirects.rN) is_redirectr1r9)rrkwargsrrrhandle_redirectszHTTPDigestAuth.handle_redirectcKs"d|jkodkns&d|j_|S|jjdk rD|jjj|jj|jjdd}d|j koh|jjdkr|jjd7_t j d t j d }t |jd|dd |j_|j|j|jj}t|j|j|j|j|j|j|j|j|jd <|jj|f|}|jj|||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response iirNzwww-authenticater3digestzdigest )flags)countr+) status_coder1r9r8requestbodyseekr,rWlowerrecompile IGNORECASEr subr7contentclosecopyr_cookiesrawprepare_cookiesror`ra connectionsendhistoryappend)rrrqs_authpatprep_rrrr handle_401s.     zHTTPDigestAuth.handle_401c Cs~|j|jjr&|j|j|j|jd<y|jj|j_ Wnt k rTd|j_ YnX|j d|j |j d|j d|j_|S)Nr+responser)r:r1r5ror`rar,rytellr8AttributeError register_hookrrrr9)rrrrrrszHTTPDigestAuth.__call__cCs(t|jt|ddk|jt|ddkgS)Nrr)r&rr'r)rr(rrrr)*szHTTPDigestAuth.__eq__cCs ||k S)Nr)rr(rrrr*0szHTTPDigestAuth.__ne__N) r r!r"r#r%r:rorrrrr)r*rrrrr.ls f,r.)r#r]r|r[rAr/rbase64rcompatrrrcookiesr_internal_utilsrutilsr CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTrobjectrr$r-r.rrrrs$    ,