]> jfr.im git - z_archive/twitter.git/commitdiff
If invalid values are passed for secrets, raise an exception with a helpful error...
authorJessamyn Smith <redacted>
Mon, 20 Apr 2015 17:07:46 +0000 (13:07 -0400)
committerJessamyn Smith <redacted>
Mon, 20 Apr 2015 17:07:46 +0000 (13:07 -0400)
twitter/auth.py
twitter/oauth.py
twitter/oauth2.py

index 77633fff6eca0b166a72b1c0ea8af75628b16bbc..45f1f4c001ae21df31a0aa904a5aad06aafaee97 100644 (file)
@@ -5,6 +5,7 @@ except ImportError:
     import urllib as urllib_parse
     from base64 import encodestring as encodebytes
 
+
 class Auth(object):
     """
     ABC for Authenticator objects.
@@ -21,6 +22,7 @@ class Auth(object):
         by the authentication scheme in use."""
         raise NotImplementedError()
 
+
 class UserPassAuth(Auth):
     """
     Basic auth authentication using email/username and
@@ -41,6 +43,7 @@ class UserPassAuth(Auth):
                 .encode('utf8')).strip(b'\n')
                 }
 
+
 class NoAuth(Auth):
     """
     No authentication authenticator.
@@ -53,3 +56,7 @@ class NoAuth(Auth):
 
     def generate_headers(self):
         return {}
+
+
+class MissingCredentialsError(Exception):
+    pass
index 2df5ff0a1eb9a0319d6ad959ac21702d2edd05de..b0d7f41b4bc77aec6c7f85a8172413d89e714ba3 100644 (file)
@@ -57,7 +57,7 @@ import hashlib
 import hmac
 import base64
 
-from .auth import Auth
+from .auth import Auth, MissingCredentialsError
 
 
 def write_token_file(filename, oauth_token, oauth_token_secret):
@@ -92,6 +92,10 @@ class OAuth(Auth):
         self.consumer_key = consumer_key
         self.consumer_secret = consumer_secret
 
+        if token_secret is None or consumer_secret is None:
+            raise MissingCredentialsError(
+                'You must supply strings for token_secret and consumer_secret, not None.')
+
     def encode_params(self, base_url, method, params):
         params = params.copy()
 
index 6c69c2b59cbdd648a0389a9508e6bc20dff3cfd1..fb5fefe9e4543aefb534b8d67ae76c354d3d8c82 100644 (file)
@@ -31,7 +31,7 @@ except ImportError:
     from urllib import quote, urlencode
 
 from base64 import b64encode
-from .auth import Auth
+from .auth import Auth, MissingCredentialsError
 
 def write_bearer_token_file(filename, oauth2_bearer_token):
     """
@@ -89,7 +89,3 @@ class OAuth2(Auth):
                 ).encode('utf8')
             }
         return headers
-
-
-class MissingCredentialsError(Exception):
-    pass