pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

python private pastebin - collaborative debugging tool What's a private pastebin?


Posted by hs on Tue 24 Mar 05:19
report abuse | download | new post

  1. #!/usr/bin/python
  2.  
  3. import oauth, httplib, urllib
  4.  
  5. KEY = '' #Fill me in
  6. SECRET = '' #Fill me in
  7. SERVER = 'www.jaiku.com'
  8. REQURL = '/api/request_token'
  9. ACCURL = '/api/access_token'
  10. AUTURL = 'http://www.jaiku.com/api/authorize'
  11.  
  12. class MyOAuthClient(oauth.OAuthClient):
  13.  
  14.     def __init__(self, server, request_token_url, access_token_url):
  15.         self.server = server
  16.         self.request_token_url = request_token_url
  17.         self.access_token_url = access_token_url
  18.         self.full_request_url = "http://" + self.server + self.request_token_url
  19.         self.full_access_url = "http://" + self.server + self.access_token_url
  20.         self.connection = httplib.HTTPConnection(self.server)
  21.  
  22.     def fetch_request_token(self, oauth_request):
  23.         self.connection.request('GET', self.request_token_url, headers=oauth_request.to_header())
  24.         response = self.connection.getresponse()
  25.         return oauth.OAuthToken.from_string(response.read())
  26.  
  27.     def authorize_token(self, oauth_request):
  28.         self.connection.request('GET', oauth_request.to_url())
  29.         response = self.connection.getresponse()
  30.         return response.read()
  31.  
  32.     def fetch_access_token(self, oauth_request):
  33.         self.connection.request('GET', self.access_token_url, headers=oauth_request.to_header())
  34.         response = self.connection.getresponse()
  35.         return oauth.OAuthToken.from_string(response.read())
  36.  
  37. if __name__ == "__main__":
  38.     import os, re
  39.  
  40.     client = MyOAuthClient(SERVER, REQURL, ACCURL)
  41.     consumer = oauth.OAuthConsumer(KEY, SECRET)
  42.     sig_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
  43.  
  44.     oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_url=client.full_request_url)
  45.     oauth_request.sign_request(sig_method, consumer, None)
  46.     token = client.fetch_request_token(oauth_request)
  47.     print "*** Obtained request token."
  48.  
  49.     oauth_request = oauth.OAuthRequest.from_token_and_callback(token, http_url=AUTURL)
  50.     response = client.authorize_token(oauth_request)
  51.     m = re.search('HREF="(.+)"', response)
  52.     print "*** Please login to this URL:\n" + m.group(1)
  53.     os.system('pause')
  54.  
  55.     oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_url=client.full_access_url)
  56.     oauth_request.sign_request(sig_method, consumer, token)
  57.     token = client.fetch_access_token(oauth_request)
  58.     print "*** Got access token:\n" + str(token)

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post