]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/oauth.py
make cmd client understand any language
[z_archive/twitter.git] / twitter / oauth.py
index a839bb6a9e7303980a166b925462b8bb1df89e2c..ed15492ac576a9a0b3529f9db8070175b72203a3 100644 (file)
@@ -8,6 +8,23 @@ import hashlib
 import hmac
 
 
+def write_token_file(filename, oauth_token, oauth_token_secret):
+    """
+    Write a token file to hold the oauth token and oauth token secret.
+    """
+    oauth_file = open(filename, 'w')
+    print >> oauth_file, oauth_token
+    print >> oauth_file, oauth_token_secret
+    oauth_file.close()
+
+def read_token_file(filename):
+    """
+    Read a token file and return the oauth token and oauth token secret.
+    """
+    f = open(filename)
+    return f.readline().strip(), f.readline().strip()
+
+
 class OAuth(Auth):
     """
     An OAuth authenticator.
@@ -41,7 +58,7 @@ class OAuth(Auth):
 
         message = '&'.join(
             urllib.quote(i, '') for i in [method.upper(), base_url, enc_params])
-    
+
         signature = hmac.new(
             key, message, hashlib.sha1).digest().encode('base64')[:-1]
         return enc_params + "&" + "oauth_signature=" + urllib.quote(signature, '')
@@ -57,7 +74,7 @@ def urlencode_noplus(query):
     if hasattr(query,"items"):
         # mapping objects
         query = query.items()
-    
+
     encoded_bits = []
     for n, v in query:
         # and do unicode here while we are at it...