ž 7’Reλc@sπdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z dZd Zd d „ZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZdS(u] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. iN(u b64encodei(uurlparseustr(uextract_cookies_to_jar(uparse_dict_headeru!application/x-www-form-urlencodedumultipart/form-datacCs0dtd||fjdƒƒjƒjdƒS(uReturns a Basic Auth string.uBasic u%s:%sulatin1(u b64encodeuencodeustripudecode(uusernameupassword((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu_basic_auth_strsu_basic_auth_strcBs&|EeZdZdZdd„ZdS(uAuthBaseu4Base class that all auth implementations derive fromcCstdƒ‚dS(NuAuth hooks must be callable.(uNotImplementedError(uselfur((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu__call__"suAuthBase.__call__N(u__name__u __module__u __qualname__u__doc__u__call__(u __locals__((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyuAuthBasesuAuthBasecBs2|EeZdZdZdd„Zdd„ZdS(u HTTPBasicAuthu?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(uusernameupassword(uselfuusernameupassword((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu__init__(s uHTTPBasicAuth.__init__cCs t|j|jƒ|jd<|S(Nu Authorization(u_basic_auth_struusernameupassworduheaders(uselfur((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu__call__,suHTTPBasicAuth.__call__N(u__name__u __module__u __qualname__u__doc__u__init__u__call__(u __locals__((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu HTTPBasicAuth&s u HTTPBasicAuthcBs&|EeZdZdZdd„ZdS(u HTTPProxyAuthu=Attaches HTTP Proxy Authentication to a given Request object.cCs t|j|jƒ|jd<|S(NuProxy-Authorization(u_basic_auth_struusernameupassworduheaders(uselfur((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu__call__3suHTTPProxyAuth.__call__N(u__name__u __module__u __qualname__u__doc__u__call__(u __locals__((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu HTTPProxyAuth1su HTTPProxyAuthcBsJ|EeZdZdZdd„Zdd„Zdd„Zdd „Zd S( uHTTPDigestAuthu@Attaches HTTP Digest Authentication to the given Request object.cCs:||_||_d|_d|_i|_d|_dS(Nui(uusernameupasswordu last_nonceu nonce_countuchaluNoneupos(uselfuusernameupassword((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu__init__:s      uHTTPDigestAuth.__init__cs6|jd}|jd}|jjdƒ}|jjdƒ}|jjdƒ}|dkred}n |jƒ}|dks‰|dkrždd „} | ‰n!|d krΏd d „} | ‰n‡fd d†} ˆdkrαdSd} t|ƒ} | j}| jr|d| j7}nd|j||jf}d||f}ˆ|ƒ}ˆ|ƒ}||j kr{|j d7_ n d|_ d|j }t |j ƒj dƒ}||j dƒ7}|t jƒj dƒ7}|tjdƒ7}tj|ƒjƒdd…}d|||||f}|dkrHˆd|||fƒ}n|dkrp| |d||fƒ}n7|dks‘d|jdƒkr£| ||ƒ}ndS||_ d|j||||f}|rγ|d|7}n|rϊ|d|7}n| r|d| 7}n|r.|d||f7}nd|S( Nurealmunonceuqopu algorithmuopaqueuMD5uMD5-SESScSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nuutf-8(u isinstanceustruencodeuhashlibumd5u hexdigest(ux((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyumd5_utf8Psu4HTTPDigestAuth.build_digest_header..md5_utf8uSHAcSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nuutf-8(u isinstanceustruencodeuhashlibusha1u hexdigest(ux((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyusha_utf8Vsu4HTTPDigestAuth.build_digest_header..sha_utf8csˆd||fƒS(Nu%s:%s((usud(u hash_utf8(u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu\su4HTTPDigestAuth.build_digest_header..u?u%s:%s:%su%s:%siu%08xuutf-8iiu%s:%s:%s:%s:%suauthu,u>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"u , opaque="%s"u, algorithm="%s"u , digest="%s"u , qop="auth", nc=%s, cnonce="%s"u Digest %s(uchalugetuNoneuupperuurlparseupathuqueryuusernameupasswordu last_nonceu nonce_countustruencodeutimeuctimeuosuurandomuhashlibusha1u hexdigestusplit(uselfumethoduurlurealmunonceuqopu algorithmuopaqueu _algorithmumd5_utf8usha_utf8uKDuentdigup_parsedupathuA1uA2uHA1uHA2uncvalueusucnonceunoncebiturespdigubase((u hash_utf8u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyubuild_digest_headerBsn                    ! u"HTTPDigestAuth.build_digest_headercKsk|jd k r(|jjj|jƒnt|ddƒ}|jjddƒ}d|jƒkrW|dkrWt |d|dƒt j ddt j ƒ}t |jd|d dƒƒ|_|j|jjƒ|jjƒ}t|j|j|jƒ|j|jƒ|j|j|jƒ|jd <|jj||}|jj|ƒ||_|St |ddƒ|S( u:Takes the given response and tries digest-auth, if needed.u num_401_callsiuwww-authenticateuudigestiudigest uflagsucountu AuthorizationN(uposuNoneurequestubodyuseekugetattruheadersugetulowerusetattrureucompileu IGNORECASEuparse_dict_headerusubuchalucontenturawu release_connucopyuextract_cookies_to_jaru_cookiesuprepare_cookiesubuild_digest_headerumethoduurlu connectionusenduhistoryuappend(uselfurukwargsu num_401_callsus_authupatuprepu_r((u2/tmp/pip-zej_zi-build/pip/_vendor/requests/auth.pyu handle_401•s*!  uHTTPDigestAuth.handle_401c Csm|jr+|j|j|jƒ|jds