<s> from __future__ import unicode_literals <EOL> from oauthlib . common import extract_params <EOL> from oauthlib . oauth1 import ( Client , SIGNATURE_HMAC , SIGNATURE_TYPE_AUTH_HEADER ) <EOL> CONTENT_TYPE_FORM_URLENCODED = '<STR_LIT>' <EOL> CONTENT_TYPE_MULTI_PART = '<STR_LIT>' <EOL> import sys <EOL> if sys . version > "<STR_LIT:3>" : <EOL> unicode = str <EOL> def to_native_str ( string ) : <EOL> return string . decode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> def to_native_str ( string ) : <EOL> return string <EOL> class OAuth1 ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client_key , <EOL> client_secret = None , <EOL> resource_owner_key = None , <EOL> resource_owner_secret = None , <EOL> callback_uri = None , <EOL> signature_method = SIGNATURE_HMAC , <EOL> signature_type = SIGNATURE_TYPE_AUTH_HEADER , <EOL> rsa_key = None , verifier = None , <EOL> decoding = '<STR_LIT:utf-8>' ) : <EOL> try : <EOL> signature_type = signature_type . upper ( ) <EOL> except AttributeError : <EOL> pass <EOL> self . client = Client ( client_key , client_secret , resource_owner_key , <EOL> resource_owner_secret , callback_uri , signature_method , <EOL> signature_type , rsa_key , verifier , decoding = decoding ) <EOL> def __call__ ( self , r ) : <EOL> """<STR_LIT>""" <EOL> content_type = r . headers . get ( '<STR_LIT:Content-Type>' . encode ( '<STR_LIT:utf-8>' ) , '<STR_LIT>' ) <EOL> if not isinstance ( content_type , unicode ) : <EOL> content_type = content_type . decode ( '<STR_LIT:utf-8>' ) <EOL> is_form_encoded = ( CONTENT_TYPE_FORM_URLENCODED in content_type ) <EOL> if is_form_encoded or extract_params ( r . body ) : <EOL> r . headers [ '<STR_LIT:Content-Type>' ] = CONTENT_TYPE_FORM_URLENCODED <EOL> r . url , r . headers , r . body = self . client . sign ( <EOL> unicode ( r . url ) , unicode ( r . method ) , r . body or '<STR_LIT>' , r . headers ) <EOL> else : <EOL> r . url , r . headers , _ = self . client . sign ( <EOL> unicode ( r . url ) , unicode ( r . method ) , None , r . headers ) <EOL> r . url = to_native_str ( r . url ) <EOL> return r </s>
