?RTc@sdZddlZddlZddlZddlZddlZddlZddlZdZdZ dZ de fdYZ dd Z d Zd Zd Zd dZd dZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZd efd!YZdS("s1 The MIT License Copyright (c) 2007 Leah Culver Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. iNs1.0tGETt PLAINTEXTt OAuthErrorcBseZdZddZRS(sGeneric exception class.sOAuth error occured.cCs ||_dS(N(tmessage(tselfR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt__init__)s(t__name__t __module__t__doc__R(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR'stcCsid|d6S(s,Optional WWW-Authenticate header (401 error)sOAuth realm="%s"sWWW-Authenticate((trealm((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytbuild_authenticate_header,scCstj|ddS(sEscape a URL including any /.tsafet~(turllibtquote(ts((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytescape0scCs*t|tr|jdSt|SdS(sConvert unicode to utf-8.sutf-8N(t isinstancetunicodetencodetstr(R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt _utf8_str4s cCsttjS(sGet seconds since epoch (UTC).(tintttime(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytgenerate_timestamp;sicCs8djgt|D]}ttjdd^qS(sGenerate pseudorandom number.R ii (tjointrangeRtrandomtrandint(tlengthti((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytgenerate_nonce?scCs8djgt|D]}ttjdd^qS(sGenerate pseudorandom number.R ii (RRRRR(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytgenerate_verifierCst OAuthConsumercBs#eZdZdZdZdZRS(sConsumer of OAuth authentication. OAuthConsumer is a data type that represents the identity of the Consumer via its shared secret with the Service Provider. cCs||_||_dS(N(tkeytsecret(RR#R$((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRRs N(RRRtNoneR#R$R(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR"Hst OAuthTokencBszeZdZdZdZdZdZdZdZ dZ ddZ dZ dZ dZeeZdZRS( sOAuthToken is a data type that represents an End User via either an access or request token. key -- the token secret -- the token secret cCs||_||_dS(N(R#R$(RR#R$((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRes cCs||_d|_dS(Nttrue(tcallbacktcallback_confirmed(RR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt set_callbackis cCs(|dk r||_n t|_dS(N(R%tverifierR!(RR+((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt set_verifierms  cCs|jr|jrtj|j}|d \}}}}}}|r\d||jf}n d|j}tj||||||fS|jS(Nis%s&oauth_verifier=%ssoauth_verifier=%s(R(R+turlparset urlunparse(Rtpartstschemetnetloctpathtparamstquerytfragment((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytget_callback_urlss  cCsFi|jd6|jd6}|jdk r9|j|dR?R@RRRR(RtRIRTRU((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRoisN(RRRR%RIt HTTP_METHODRGRHtVERSIONR{RRLRMRPRVRYR[R]RbRdR\RlRiRvRER~RRmRo(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRFs@          !       t OAuthServercBseZdZdZeZdZdZdddZ dZ dZ dZ dZ dZdZd Zd Zd d Zd ZdZdZddZdZdZdZdZRS(sAA worker to check the validity of a request against a data store.i,cCs||_|pi|_dS(N(t data_storetsignature_methods(RRR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRxs cCs ||_dS(N(R(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytset_data_store|scCs|jS(N(R(R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytget_data_storescCs||j|j<|jS(N(RRh(RRj((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytadd_signature_methodscCsy|j|d}Wntk r|j|}|j|}y|j|}Wntk rpd}nX|j||d|jj||}nX|S(s\Processes a request_token request and returns the request token on success. trequestN( t _get_tokenRt _get_versiont _get_consumert get_callbackR%t_check_signatureRtfetch_request_token(Rt oauth_requestRBR{RkR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs   cCs|j|}|j|}y|j|}Wntk rJd}nX|j|d}|j||||jj|||}|S(s[Processes an access_token request and returns the access token on success. RN( RRt _get_verifierRR%RRRtfetch_access_token(RRR{RkR+RBt new_token((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs  cCs\|j|}|j|}|j|d}|j||||j}|||fS(s3Verifies an api call and checks all the parameters.taccess(RRRRRV(RRR{RkRBRI((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytverify_requests  cCs|jj||S(sAuthorize a request token.(Rtauthorize_request_token(RRBtuser((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytauthorize_tokenscCs |jdS(sGet the callback URL.Ry(RM(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRsR cCsid|d6S(s-Optional support for the authenticate header.sOAuth realm="%s"sWWW-Authenticate((RR ((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR scCsUy|jd}Wn t}nX|rQ||jkrQtdt|n|S(s3Verify the correct version request for this server.RxsOAuth version %s not supported.(RMRR{RR(RRR{((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs cCspy|jd}Wn t}nXy|j|}Wn5dj|jj}td||fnX|S(s,Figure out the signature with some defaults.Rgs, s>Signature method %s not supported try one of the following: %s(RMtSIGNATURE_METHODRRtkeysR(RRRjtsignature_method_names((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt_get_signature_methods  cCs:|jd}|jj|}|s6tdn|S(NRwsInvalid consumer.(RMRtlookup_consumerR(RRt consumer_keyRk((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs RcCsG|jd}|jj||}|sCtd||fn|S(s9Try to find the token for the provided request token key.R7sInvalid %s token: %s(RMRt lookup_tokenR(RRt token_typet token_fieldRB((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs cCs |jdS(NRz(RM(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRsc Cs|j\}}|j||j||||j|}y|jd}WntdnX|j||||}|s|j|||\} } td| n|j|||} dS(NR^sMissing signature.s5Invalid signature. Expected signature base string: %s( RPt_check_timestampt _check_nonceRRMRtcheck_signaturetbuild_signature_base_stringRi( RRRkRBt timestamptnonceRjt signaturet valid_sigR#tbasetbuilt((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs     cCsZt|}ttj}||}||jkrVtd|||jfndS(s#Verify that timestamp is recentish.sQExpired timestamp: given %d and now %s has a greater difference than threshold %dN(RRttimestamp_thresholdR(RRtnowtlapsed((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs   cCs;|jj|||}|r7tdt|ndS(s#Verify that the nonce is uniqueish.sNonce already used: %sN(Rt lookup_nonceRR(RRkRBR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR sN(RRRRRR{R%RRRRRRRRRRRR RRRRRRRR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRqs.              t OAuthClientcBsPeZdZdZdZdZdZdZdZ dZ dZ RS(s8OAuthClient is a worker to attempt to execute a request.cCs||_||_dS(N(RkRB(RR|R7((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs cCs|jS(N(Rk(R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt get_consumerscCs|jS(N(RB(R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyt get_tokenscCs tdS(s-> OAuthToken.N(tNotImplementedError(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR!scCs tdS(s-> OAuthToken.N(R(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR%scCs tdS(s-> Some protected resource.N(R(RR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pytaccess_resource)sN( RRRR%RkRBRRRRRR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs     tOAuthDataStorecBsDeZdZdZdZdZdZdZdZRS(s;A database abstraction used to lookup consumers and tokens.cCs tdS(s-> OAuthConsumer.N(R(RR#((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR1scCs tdS(s-> OAuthToken.N(R(RR|Rt token_token((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR5scCs tdS(s-> OAuthToken.N(R(RR|R7R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR9scCs tdS(s-> OAuthToken.N(R(RR|Ry((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR=scCs tdS(s-> OAuthToken.N(R(RR|R7Rz((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRAscCs tdS(s-> OAuthToken.N(R(RR7R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyREs( RRRRRRRRR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR.s     tOAuthSignatureMethodcBs2eZdZdZdZdZdZRS(s4A strategy class that implements a signature method.cCs tdS(s-> str.N(R(R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRhLscCs tdS(s-> str key, str raw.N(R(RRR|R7((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRPscCs tdS(s-> str.N(R(RRR|R7((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRiTscCs|j|||}||kS(N(Ri(RRRkRBRR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRXs(RRRRhRRiR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRJs    tOAuthSignatureMethod_HMAC_SHA1cBs#eZdZdZdZRS(cCsdS(Ns HMAC-SHA1((R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRh_scCs{t|jt|jt|jf}dt|j}|rb|t|j7}ndj|}||fS(Ns%s&RZ(RRdR\RbR$R(RRRkRBtsigR#traw((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRbsc Cs|j|||\}}y(ddl}tj|||j}Wn(ddl}tj|||}nXtj|jd S(s!Builds the base signature string.iN( Rthashlibthmactnewtsha1tshatbinasciit b2a_base64tdigest( RRRkRBR#RRthashedR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRios   (RRRhRRi(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyR]s  tOAuthSignatureMethod_PLAINTEXTcBs#eZdZdZdZRS(cCsdS(NR((R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRhscCs9dt|j}|r/|t|j}n||fS(s)Concatenates the consumer key and secret.s%s&(RR$(RRRkRBR((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRscCs|j|||\}}|S(N(R(RRRkRBR#R((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRis (RRRhRRi(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyRs  (RR>RRRR-RRRRRt RuntimeErrorRR RRRR R!tobjectR"R&RFRRRRRR(((s8/opt/freeware/lib/python2.7/site-packages/oauth/oauth.pyts4             E#