4Tc@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZd Zd Zd Zd efd YZdefdYZdefdYZdefdYZdS(s] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. iN(t b64encodei(turlparsetstr(textract_cookies_to_jar(tparse_dict_headertto_native_string(tcodess!application/x-www-form-urlencodedsmultipart/form-datacCs3dttd||fjdj}|S(sReturns a Basic Auth string.sBasic s%s:%stlatin1(RRtencodetstrip(tusernametpasswordtauthstr((s1/usr/lib/python2.7/site-packages/requests/auth.pyt_basic_auth_strs)tAuthBasecBseZdZdZRS(s4Base class that all auth implementations derive fromcCstddS(NsAuth hooks must be callable.(tNotImplementedError(tselftr((s1/usr/lib/python2.7/site-packages/requests/auth.pyt__call__'s(t__name__t __module__t__doc__R(((s1/usr/lib/python2.7/site-packages/requests/auth.pyR$st HTTPBasicAuthcBs eZdZdZdZRS(s?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(R R (RR R ((s1/usr/lib/python2.7/site-packages/requests/auth.pyt__init__-s cCs t|j|j|jd<|S(Nt Authorization(R R R theaders(RR((s1/usr/lib/python2.7/site-packages/requests/auth.pyR1s(RRRRR(((s1/usr/lib/python2.7/site-packages/requests/auth.pyR+s t HTTPProxyAuthcBseZdZdZRS(s=Attaches HTTP Proxy Authentication to a given Request object.cCs t|j|j|jd<|S(NsProxy-Authorization(R R R R(RR((s1/usr/lib/python2.7/site-packages/requests/auth.pyR8s(RRRR(((s1/usr/lib/python2.7/site-packages/requests/auth.pyR6stHTTPDigestAuthcBs;eZdZdZdZdZdZdZRS(s@Attaches HTTP Digest Authentication to the given Request object.cCsC||_||_d|_d|_i|_d|_d|_dS(Ntii(R R t last_noncet nonce_counttchaltNonetpost num_401_calls(RR R ((s1/usr/lib/python2.7/site-packages/requests/auth.pyR?s      cs'|jd}|jd}|jjd}|jjd}|jjd}|dkred}n |j}|dks|dkrd} | n|d krd } | nfd } dkrdSd} t|} | j}| jr|d | j7}nd |j||jf}d||f}|}|}||j krr|j d7_ n d|_ d|j }t |j j d}||j d7}|t jj d7}|tjd7}tj|jd }|dkr d |||f}n|dkrH| |d||f}nP|dksid|jdkrd|||d|f}| ||}ndS||_ d|j||||f}|r|d|7}n|r|d|7}n| r|d| 7}n|r|d||f7}nd|S(Ntrealmtnoncetqopt algorithmtopaquetMD5sMD5-SESScSs4t|tr!|jd}ntj|jS(Nsutf-8(t isinstanceRRthashlibtmd5t hexdigest(tx((s1/usr/lib/python2.7/site-packages/requests/auth.pytmd5_utf8VstSHAcSs4t|tr!|jd}ntj|jS(Nsutf-8(R)RRR*tsha1R,(R-((s1/usr/lib/python2.7/site-packages/requests/auth.pytsha_utf8\scsd||fS(Ns%s:%s((tstd(t hash_utf8(s1/usr/lib/python2.7/site-packages/requests/auth.pytbst?s%s:%s:%ss%s:%sis%08xsutf-8iitautht,s%s:%s:%s:%s:%ss>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(RtgetR tupperRtpathtqueryR R RRRRttimetctimetosturandomR*R0R,tsplit(RtmethodturlR#R$R%R&R't _algorithmR.R1tKDtentdigtp_parsedR;tA1tA2tHA1tHA2tncvalueR2tcnoncetrespdigtnoncebittbase((R4s1/usr/lib/python2.7/site-packages/requests/auth.pytbuild_digest_headerHsp                    ! cKs|jrd|_ndS(s)Reset num_401_calls counter on redirects.iN(t is_redirectR"(RRtkwargs((s1/usr/lib/python2.7/site-packages/requests/auth.pythandle_redirects cKs_|jd k r(|jjj|jnt|dd}|jjdd}d|jkrR|dkrR|j d7_ t j ddt j }t |jd|d d|_|j|jj|jj}t|j|j|j|j|j|j|j|j|jd <|jj||}|jj|||_|Sd|_ |S( s:Takes the given response and tries digest-auth, if needed.R"iswww-authenticateRtdigestisdigest tflagstcountRN(R!R trequesttbodytseektgetattrRR9tlowerR"tretcompilet IGNORECASERtsubRtcontenttrawt release_conntcopyRt_cookiestprepare_cookiesRQRBRCt connectiontsendthistorytappend(RRRSR"ts_authtpattprept_r((s1/usr/lib/python2.7/site-packages/requests/auth.pyt handle_401s*!   cCs|jr+|j|j|j|jds