<s> import django . test . client as client <EOL> import django . test as test <EOL> from django . utils . http import urlencode <EOL> from piston import oauth <EOL> from piston . models import Consumer , Token <EOL> import httplib2 , urllib , cgi <EOL> URLENCODED_FORM_CONTENT = '<STR_LIT>' <EOL> class OAuthClient ( client . Client ) : <EOL> def __init__ ( self , consumer , token ) : <EOL> self . token = oauth . OAuthToken ( token . key , token . secret ) <EOL> self . consumer = oauth . OAuthConsumer ( consumer . key , consumer . secret ) <EOL> self . signature = oauth . OAuthSignatureMethod_HMAC_SHA1 ( ) <EOL> super ( OAuthClient , self ) . __init__ ( ) <EOL> def request ( self , ** request ) : <EOL> params = { } <EOL> if request [ '<STR_LIT>' ] in ( '<STR_LIT:POST>' , '<STR_LIT>' ) : <EOL> if request [ '<STR_LIT>' ] == URLENCODED_FORM_CONTENT : <EOL> payload = request [ '<STR_LIT>' ] . read ( ) <EOL> request [ '<STR_LIT>' ] = client . FakePayload ( payload ) <EOL> params = cgi . parse_qs ( payload ) <EOL> url = "<STR_LIT>" + request [ '<STR_LIT>' ] <EOL> req = oauth . OAuthRequest . from_consumer_and_token ( <EOL> self . consumer , token = self . token , <EOL> http_method = request [ '<STR_LIT>' ] , http_url = url , <EOL> parameters = params <EOL> ) <EOL> req . sign_request ( self . signature , self . consumer , self . token ) <EOL> headers = req . to_header ( ) <EOL> request [ '<STR_LIT>' ] = headers [ '<STR_LIT>' ] <EOL> return super ( OAuthClient , self ) . request ( ** request ) <EOL> def post ( self , path , data = { } , content_type = None , follow = False , ** extra ) : <EOL> if content_type is None : <EOL> content_type = URLENCODED_FORM_CONTENT <EOL> if isinstance ( data , dict ) : <EOL> data = urlencode ( data ) <EOL> return super ( OAuthClient , self ) . post ( path , data , content_type , follow , ** extra ) <EOL> class TestCase ( test . TestCase ) : <EOL> pass <EOL> class OAuthTestCase ( TestCase ) : <EOL> @ property <EOL> def oauth ( self ) : <EOL> return OAuthClient ( self . consumer , self . token ) </s>
