Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/oauth/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/oauth/oauth.pyc


,Jc@sdZddlZddlZddlZddlZddlZddlZddlZdZdZ	dZ
defdYZdd	Z
d
ZdZd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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt__init__)s(t__name__t
__module__t__doc__R(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR'stcCsid|d6S(s,Optional WWW-Authenticate header (401 error)sOAuth realm="%s"sWWW-Authenticate((trealm((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytbuild_authenticate_header,scCstj|ddS(sEscape a URL including any /.tsafet~(turllibtquote(ts((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytescape0scCs*t|tr|jdSt|SdS(sConvert unicode to utf-8.sutf-8N(t
isinstancetunicodetencodetstr(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt	_utf8_str4s
cCsttjS(sGet seconds since epoch (UTC).(tintttime(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytgenerate_timestamp;sicCs8djgt|D]}ttjdd^qS(sGenerate pseudorandom number.R	ii	(tjointrangeRtrandomtrandint(tlengthti((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytgenerate_nonce?scCs8djgt|D]}ttjdd^qS(sGenerate pseudorandom number.R	ii	(RRRRR(RR((s//usr/lib/python2.7/dist-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$((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRRs	N(RRRtNoneR#R$R(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR"Hst
OAuthTokencBszeZdZdZdZdZdZdZdZ	dZ
ddZdZ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$((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRes	cCs||_d|_dS(Nttrue(tcallbacktcallback_confirmed(RR(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytset_callbackis	cCs(|dk	r||_nt|_dS(N(R%tverifierR!(RR+((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytget_callback_urlss

cCsFi|jd6|jd6}|jdk	r9|j|d<ntj|S(Ntoauth_tokentoauth_token_secrettoauth_callback_confirmed(R#R$R)R%Rt	urlencode(Rtdata((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt	to_strings

cCsmtj|dt}|dd}|dd}t||}y|dd|_Wntk
rhnX|S(s] Returns a token from something like:
        oauth_token_secret=xxx&oauth_token=xxx
        tkeep_blank_valuesR7iR8R9(tcgitparse_qstFalseR&R)tKeyError(RR3R#R$ttoken((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytfrom_strings
cCs
|jS(N(R<(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt__str__sN(RRRR%R#R$R(R)R+RR*R,R6R<RCtstaticmethodRD(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR&Ws			
			
tOAuthRequestcBs7eZdZdZeZdZeZ	edddZ
dZdZdZ
dZddZdZd	Zd
ZdZdZd
ZdZddddZeeZdddedddZeeZdedddZeeZdZeeZdZeeZRS(ssOAuthRequest represents the request and can be serialized.

    OAuth parameters:
        - oauth_consumer_key 
        - oauth_token
        - oauth_signature_method
        - oauth_signature 
        - oauth_timestamp 
        - oauth_nonce
        - oauth_version
        - oauth_verifier
        ... any additional parameters, as defined by the Service Provider.
    cCs%||_||_|pi|_dS(N(thttp_methodthttp_urlt
parameters(RRGRHRI((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRs		cCs||j|<dS(N(RI(Rt	parametertvalue((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt
set_parameterscCs-y|j|SWntd|nXdS(NsParameter not found: %s(RIR(RRJ((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt
get_parameterscCs|jd|jdfS(Ntoauth_timestamptoauth_nonce(RM(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt_get_timestamp_noncescCsLi}x?|jjD].\}}|jddkr|||<qqW|S(sGet any non-OAuth parameters.toauth_i(RIt	iteritemstfind(RRItktv((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytget_nonoauth_parameterss
R	cCstd|}|jrixS|jjD]?\}}|d dkr#|d|tt|f7}q#q#Wni|d6S(s.Serialize as a header for an HTTPAuth request.sOAuth realm="%s"iRQs	, %s="%s"t
Authorization(RIRRRR(RR
tauth_headerRTRU((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt	to_headers
	*cCsQdjg|jjD]4\}}dtt|tt|f^qS(s*Serialize as post data for a POST request.t&s%s=%s(RRIRRRR(RRTRU((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytto_postdatas	cCsd|j|jfS(s%Serialize as a URL for a GET request.s%s?%s(tget_normalized_http_urlR[(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytto_urlscCs|j}y|d=WnnXg|jD]0\}}tt|tt|f^q+}|jdjg|D]\}}d||f^qxS(sAReturn a string that contains the parameters that must be signed.toauth_signatureRZs%s=%s(RItitemsRRtsortR(RR3RTRUt
key_values((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytget_normalized_parameterss	@
cCs
|jjS(sUppercases the http method.(RGtupper(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytget_normalized_http_methodscCstj|j}|d \}}}|dkrN|ddkrN|d }n)|dkrw|ddkrw|d }nd|||fS(	s8Parses the URL and rebuilds it to be scheme://host/path.ithttpis:80thttpsis:443s	%s://%s%s(R-RH(RR/R0R1R2((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR\s

cCs9|jd|j|jd|j|||dS(s=Set the signature parameter to the result of build_signature.toauth_signature_methodR^N(RLtget_nametbuild_signature(Rtsignature_methodtconsumerRB((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytsign_requests	
	cCs|j|||S(s=Calls the build signature method within the signature method.(Ri(RRjRkRB((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRisc
Cs|dkri}n|rd|kr|d}|d dkr|d}y tj|}|j|WqtdqXqn|rtj|}|j|ntj|d}tj|}	|j|	|rt|||SdS(s$Combines multiple parameter sources.RWisOAuth s;Unable to parse OAuth parameters from Authorization header.iN(R%RFt
_split_headertupdateRt_split_url_stringR-(
RGRHtheadersRItquery_stringRXt
header_paramstquery_paramst	param_strt
url_params((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytfrom_request	s(	


cCs|si}ni|jd6td6td6tjd6}|j||}|r|j|d<|jr||j|d<n|r||d<qn|r||d<nt|||S(Ntoauth_consumer_keyRNROt
oauth_versionR7toauth_callbacktoauth_verifier(R#RR RFtversionRnR((toauth_consumerRBR(R+RGRHRItdefaults((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytfrom_consumer_and_token-s$	





	
cCs?|si}n|j|d<|r/||d<nt|||S(NR7Ry(R#RF(RBR(RGRHRI((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytfrom_token_and_callbackKs	

cCsi}|jd}xk|D]c}|jddkr=qn|j}|jdd}tj|djd||d<qW|S(s+Turn Authorization: header into parameters.t,R
it=is"i(tsplitRStstripRtunquote(theaderR3R/tparamtparam_parts((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRmXs
(cCsMtj|dt}x1|jD]#\}}tj|d||<q"W|S(s Turn URL string into parameters.R=i(R>R?R@RRRR(RtRIRTRU((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRoisN(RRRR%RItHTTP_METHODRGRHtVERSIONR{RRLRMRPRVRYR[R]RbRdR\RlRiRvRER~RRmRo(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRFs@
					
								!	
		tOAuthServercBseZdZdZeZdZdZdddZ	dZ
dZdZdZ
dZdZd	Zd
Zdd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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRxs	cCs
||_dS(N(R(RR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytset_data_store|scCs|jS(N(R(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytget_data_storescCs||j|j<|jS(N(RRh(RRj((s//usr/lib/python2.7/dist-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(((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytverify_requestscCs|jj||S(sAuthorize a request token.(Rtauthorize_request_token(RRBtuser((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytauthorize_tokenscCs
|jdS(sGet the callback URL.Ry(RM(RR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRsR	cCsid|d6S(s-Optional support for the authenticate header.sOAuth realm="%s"sWWW-Authenticate((RR
((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRscCsUy|jd}Wn
t}nX|rQ||jkrQtdt|n|S(s3Verify the correct version request for this server.RxsOAuth version %s not supported.(RMRR{RR(RRR{((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt_get_signature_methods

cCs:|jd}|jj|}|s6tdn|S(NRwsInvalid consumer.(RMRtlookup_consumerR(RRtconsumer_keyRk((s//usr/lib/python2.7/dist-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_typettoken_fieldRB((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRs
cCs
|jdS(NRz(RM(RR((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRs
cCs;|jj|||}|r7tdt|ndS(s#Verify that the nonce is uniqueish.sNonce already used: %sN(Rtlookup_nonceRR(RRkRBR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRsN(RRRRRR{R%RRRRRRRRRRRRRRRRRRRR(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRqs.									
					
tOAuthClientcBsPeZdZdZdZdZdZdZdZ	dZ
dZRS(s8OAuthClient is a worker to attempt to execute a request.cCs||_||_dS(N(RkRB(RR|R7((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRs	cCs|jS(N(Rk(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytget_consumerscCs|jS(N(RB(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt	get_tokenscCs
tdS(s-> OAuthToken.N(tNotImplementedError(RR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR!scCs
tdS(s-> OAuthToken.N(R(RR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR%scCs
tdS(s-> Some protected resource.N(R(RR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pytaccess_resource)sN(RRRR%RkRBRRRRRR(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRs					tOAuthDataStorecBsDeZdZdZdZdZdZdZdZRS(s;A database abstraction used to lookup consumers and tokens.cCs
tdS(s-> OAuthConsumer.N(R(RR#((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR1scCs
tdS(s-> OAuthToken.N(R(RR|Rttoken_token((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR5scCs
tdS(s-> OAuthToken.N(R(RR|R7R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR9scCs
tdS(s-> OAuthToken.N(R(RR|Ry((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR=scCs
tdS(s-> OAuthToken.N(R(RR|R7Rz((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRAscCs
tdS(s-> OAuthToken.N(R(RR7R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyREs(	RRRRRRRRR(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR.s					tOAuthSignatureMethodcBs2eZdZdZdZdZdZRS(s4A strategy class that implements a signature method.cCs
tdS(s-> str.N(R(R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRhLscCs
tdS(s-> str key, str raw.N(R(RRR|R7((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRPscCs
tdS(s-> str.N(R(RRR|R7((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRiTscCs|j|||}||kS(N(Ri(RRRkRBRR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRXs(RRRRhRRiR(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRJs
			tOAuthSignatureMethod_HMAC_SHA1cBs#eZdZdZdZRS(cCsdS(Ns	HMAC-SHA1((R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRh_scCs{t|jt|jt|jf}dt|j}|rb|t|j7}ndj|}||fS(Ns%s&RZ(RRdR\RbR$R(RRRkRBtsigR#traw((s//usr/lib/python2.7/dist-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((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRios(RRRhRRi(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyR]s		
tOAuthSignatureMethod_PLAINTEXTcBs#eZdZdZdZRS(cCsdS(NR((R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRhscCs9dt|j}|r/|t|j}n||fS(s)Concatenates the consumer key and secret.s%s&(RR$(RRRkRBR((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRscCs|j|||\}}|S(N(R(RRRkRBR#R((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRis(RRRhRRi(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyRs		(RR>RRRR-RRRRRtRuntimeErrorRRRRRR R!tobjectR"R&RFRRRRRR(((s//usr/lib/python2.7/dist-packages/oauth/oauth.pyt<module>s4			E#