o {nh'@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|tstjd|tdt|}t|ts(tjdt|tdt|}t|tr2|d}t|tr<|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)usernamepasswordauthstrr8/usr/local/lib/python3.10/dist-packages/requests/auth.py_basic_auth_strs,       rc@eZdZdZddZdS)AuthBasez4Base class that all auth implementations derive fromcCstd)NzAuth hooks must be callable.)NotImplementedErrorselfrrrr__call__HszAuthBase.__call__N__name__ __module__ __qualname____doc__r"rrrrrE rc@s0eZdZdZddZddZddZdd Zd S) HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dSN)rrr rrrrr__init__Os zHTTPBasicAuth.__init__cC(t|jt|ddk|jt|ddkgSNrrallrgetattrrr otherrrr__eq__S zHTTPBasicAuth.__eq__cC ||k Sr*rr2rrr__ne__[ zHTTPBasicAuth.__ne__cCt|j|j|jd<|S)N Authorizationrrrheadersrrrrr"^zHTTPBasicAuth.__call__N)r$r%r&r'r,r4r7r"rrrrr)Ls  r)c@r) HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCr9)NzProxy-Authorizationr;rrrrr"fr=zHTTPProxyAuth.__call__Nr#rrrrr>cr(r>c@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,nszHTTPDigestAuth.__init__cCsDt|jds d|j_d|j_d|j_i|j_d|j_d|j_dSdS)NinitTr)hasattrrBrC last_nonce nonce_countchalpos num_401_calls)r rrrinit_per_thread_statets  z$HTTPDigestAuth.init_per_thread_statec s|jjd}|jjd}|jjd}|jjd}|jjd}d|dur*d}n|}|dks6|dkr=d d } | n |d krHd d } | n|dkrSdd} | n |dkr]dd} | fdd} duridSd}t|}|jpsd}|jr|d|j7}|jd|d|j}|d|}|}|}||jj kr|jj d7_ nd|j_ |jj d}t |jj  d}|| d7}|t  d7}|td7}t|dd}|dkr|d|d|}|s| ||d|}n"|dksd|dvr|d|d|d |}| ||}ndS||j_ d!|jd"|d#|d$|d%|d& }|r?|d'|d&7}|rJ|d(|d&7}|rU|d)|d&7}|rc|d*|d+|d&7}d,|S)-z :rtype: str realmnonceqop algorithmopaqueNMD5zMD5-SESScS"t|tr |d}t|SNutf-8)r rrhashlibmd5 hexdigestxrrrmd5_utf8  z4HTTPDigestAuth.build_digest_header..md5_utf8SHAcSrRrS)r rrrUsha1rWrXrrrsha_utf8r[z4HTTPDigestAuth.build_digest_header..sha_utf8zSHA-256cSrRrS)r rrrUsha256rWrXrrr sha256_utf8r[z7HTTPDigestAuth.build_digest_header..sha256_utf8zSHA-512cSrRrS)r rrrUsha512rWrXrrr sha512_utf8r[z7HTTPDigestAuth.build_digest_header..sha512_utf8cs|d|S)N:r)sd hash_utf8rrsz4HTTPDigestAuth.build_digest_header../?rcr08xrTauth,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 )rBrHgetupperrpathqueryrrrFrGrrtimectimeosurandomrUr]rWsplit)r methodurlrLrMrNrOrP _algorithmrZr^r`rbKDentdigp_parsedrsA1A2HA1HA2ncvaluerdcnoncerespdignoncebitbaserrfrbuild_digest_header~s        z"HTTPDigestAuth.build_digest_headercKs|jr d|j_dSdS)z)Reset num_401_calls counter on redirects.rN) is_redirectrBrJ)r r!kwargsrrrhandle_redirects zHTTPDigestAuth.handle_redirectcKs"d|jkr dksnd|j_|S|jjdur!|jj|jj|jdd}d| vr|jjdkr|jjd7_t j d t j d }t |jd|dd |j_|j||j}t|j|j|j||j||j|j|jd <|jj|fi|}|j|||_|Sd|j_|S) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response iirNzwww-authenticaterDdigestzdigest )flags)countr:) status_coderBrJrIrequestbodyseekr<rqlowerrecompile IGNORECASEr subrHcontentclosecopyr_cookiesrawprepare_cookiesrrzr{ connectionsendhistoryappend)r r!rs_authpatprep_rrrr handle_401s0      zHTTPDigestAuth.handle_401cCs|||jjr||j|j|jd<z |j|j_ Wn t y)d|j_ Ynw| d|j | d|j d|j_|S)Nr:responser)rKrBrFrrzr{r<rtellrIAttributeError register_hookrrrJrrrrr"s  zHTTPDigestAuth.__call__cCr-r.r/r2rrrr41r5zHTTPDigestAuth.__eq__cCr6r*rr2rrrr79r8zHTTPDigestAuth.__ne__N) r$r%r&r'r,rKrrrr"r4r7rrrrr?ks n, r?)r'rUrwrr@rurbase64r_internal_utilsrcompatrrrcookiesrutilsr CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTrrr)r>r?rrrrs&    ,