ó b@RTc@sódZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZdZd Zd „Zd efd „ƒYZd efd„ƒYZdefd„ƒYZdefd„ƒYZdS(s] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. iÿÿÿÿN(t b64encodei(turlparsetstr(textract_cookies_to_jar(tparse_dict_headertto_native_strings!application/x-www-form-urlencodedsmultipart/form-datacCs3dttd||fjdƒƒjƒƒ}|S(sReturns a Basic Auth string.sBasic s%s:%stlatin1(RRtencodetstrip(tusernametpasswordtauthstr((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyt_basic_auth_strs)tAuthBasecBseZdZd„ZRS(s4Base class that all auth implementations derive fromcCstdƒ‚dS(NsAuth hooks must be callable.(tNotImplementedError(tselftr((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyt__call__&s(t__name__t __module__t__doc__R(((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyR #st HTTPBasicAuthcBs eZdZd„Zd„ZRS(s?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(R R (RR R ((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyt__init__,s cCs t|j|jƒ|jd<|S(Nt Authorization(R R R theaders(RR((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyR0s(RRRRR(((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyR*s t HTTPProxyAuthcBseZdZd„ZRS(s=Attaches HTTP Proxy Authentication to a given Request object.cCs t|j|jƒ|jd<|S(NsProxy-Authorization(R R R R(RR((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyR7s(RRRR(((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyR5stHTTPDigestAuthcBs2eZdZd„Zd„Zd„Zd„ZRS(s@Attaches HTTP Digest Authentication to the given Request object.cCs:||_||_d|_d|_i|_d|_dS(Nti(R R t last_noncet nonce_counttchaltNonetpos(RR R ((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyR>s      cs'|jd}|jd}|jjdƒ}|jjdƒ}|jjdƒ}|dkred}n |jƒ}|dks‰|dkr›d„} | ‰n|d kr¹d „} | ‰n‡fd †} ˆdkrØdSd} t|ƒ} | j}| jr|d | j7}nd |j||jf}d||f}ˆ|ƒ}ˆ|ƒ}||j krr|j d7_ n d|_ d|j }t |j ƒj dƒ}||j dƒ7}|t jƒj dƒ7}|tjdƒ7}tj|ƒjƒd }d|||||f}|dkr9ˆd |||fƒ}n|dkra| |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(Ntrealmtnoncetqopt algorithmtopaquetMD5sMD5-SESScSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nsutf-8(t isinstanceRRthashlibtmd5t hexdigest(tx((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pytmd5_utf8TstSHAcSs4t|tƒr!|jdƒ}ntj|ƒjƒS(Nsutf-8(R'RRR(tsha1R*(R+((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pytsha_utf8Zscsˆd||fƒS(Ns%s:%s((tstd(t hash_utf8(s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyt`st?s%s:%s:%ss%s:%sis%08xsutf-8iis%s:%s:%s:%s:%stautht,s>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"s , opaque="%s"s, algorithm="%s"s , digest="%s"s , qop="auth", nc=%s, cnonce="%s"s Digest %s(RtgetRtupperRtpathtqueryR R RRRRttimetctimetosturandomR(R.R*tsplit(RtmethodturlR!R"R#R$R%t _algorithmR,R/tKDtentdigtp_parsedR9tA1tA2tHA1tHA2tncvalueR0tcnoncetnoncebittrespdigtbase((R2s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pytbuild_digest_headerFsn                    ! cKsk|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( s:Takes the given response and tries digest-auth, if needed.t num_401_callsiswww-authenticateRtdigestisdigest tflagstcountRN(R RtrequesttbodytseektgetattrRR7tlowertsetattrtretcompilet IGNORECASERtsubRtcontenttrawt release_conntcopyRt_cookiestprepare_cookiesROR@RAt connectiontsendthistorytappend(RRtkwargsRPts_authtpattprept_r((s:/opt/freeware/lib/python2.7/site-packages/requests/auth.pyt handle_401™s*!  cCsl|jr+|j|j|jƒ|jds