o Ba_'@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|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)usernamepasswordauthstrr//usr/lib/python3/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__KszAuthBase.__call__N__name__ __module__ __qualname____doc__r"rrrrrH rc@s0eZdZdZddZddZddZdd Zd S) HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dSN)rrr rrrrr__init__Rs zHTTPBasicAuth.__init__cC(t|jt|ddk|jt|ddkgSNrrallrgetattrrr otherrrr__eq__VzHTTPBasicAuth.__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)Os  r)c@r) HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.cCr9)NzProxy-Authorizationr;rrrrr"gr=zHTTPProxyAuth.__call__Nr#rrrrr>dr(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,oszHTTPDigestAuth.__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_stateus  z$HTTPDigestAuth.init_per_thread_statecs|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}d|j||jf}d||f}|}|}||jj kr|jj d7_ nd|j_ d|jj }t |jj  d}|| d7}|t  d7}|td7}t|dd}|dkrd|||f}|s| |d||f}n|dksd|d vr d!|||d|f}| ||}ndS||j_ d"|j||||f}|r&|d#|7}|r/|d$|7}|r8|d%|7}|rC|d&||f7}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_utf8csd||fS)N%s:%sr)sd hash_utf8rrsz4HTTPDigestAuth.build_digest_header../?z%s:%s:%srcrz%08xrTauth,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)rBrHgetupperrpathqueryrrrFrGrrtimectimeosurandomrUr]rWsplit)r methodurlrLrMrNrOrP _algorithmrZr^r`rbKDentdigp_parsedrqA1A2HA1HA2ncvaluerdcnoncerespdignoncebitbaserrfrbuild_digest_headers            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<rolowerrecompile IGNORECASEr subrHcontentclosecopyr_cookiesrawprepare_cookiesrrxry 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)rKrBrFrrxryr<rtellrIAttributeError register_hookrrrJrrrrr"s  zHTTPDigestAuth.__call__cCr-r.r/r2rrrr4*r5zHTTPDigestAuth.__eq__cCr6r*rr2rrrr70r8zHTTPDigestAuth.__ne__N) r$r%r&r'r,rKrrrr"r4r7rrrrr?ls f, r?)r'rurrsrUr@rbase64rcompatrrrcookiesr_internal_utilsrutilsr CONTENT_TYPE_FORM_URLENCODEDCONTENT_TYPE_MULTI_PARTrobjectrr)r>r?rrrrs&    ,