]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/oauth.py
- Attempt to determine terminal encoding when tweeting.
[z_archive/twitter.git] / twitter / oauth.py
index 61b771d98200a3a654aaf3445355ca05fad05380..a839bb6a9e7303980a166b925462b8bb1df89e2c 100644 (file)
@@ -8,9 +8,16 @@ import hashlib
 import hmac
 
 
-# An OAuth implementation with various helpers...
 class OAuth(Auth):
+    """
+    An OAuth authenticator.
+    """
     def __init__(self, token, token_secret, consumer_key, consumer_secret):
+        """
+        Create the authenticator. If you are in the initial stages of
+        the OAuth dance and don't yet have a token or token_secret,
+        pass empty strings for these params.
+        """
         self.token = token
         self.token_secret = token_secret
         self.consumer_key = consumer_key
@@ -19,7 +26,9 @@ class OAuth(Auth):
     def encode_params(self, base_url, method, params):
         params = params.copy()
 
-        params['oauth_token'] = self.token
+        if self.token:
+            params['oauth_token'] = self.token
+
         params['oauth_consumer_key'] = self.consumer_key
         params['oauth_signature_method'] = 'HMAC-SHA1'
         params['oauth_version'] = '1.0'
@@ -33,8 +42,8 @@ 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]
+        signature = hmac.new(
+            key, message, hashlib.sha1).digest().encode('base64')[:-1]
         return enc_params + "&" + "oauth_signature=" + urllib.quote(signature, '')
 
     def generate_headers(self):