]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/auth.py
Remove agent cruft. Default to api.twitter.com and version 1.
[z_archive/twitter.git] / twitter / auth.py
index f22b088e8b037f8f9a4b0a1fd213ed3800d7951e..a3a845d14ec9bea9f9400ae3d3ef4fd24fe95b25 100644 (file)
@@ -1,4 +1,8 @@
-import urllib
+try:
+    import urllib.parse as urllib_parse
+except ImportError:
+    import urllib as urllib_parse
+
 from base64 import encodestring
 
 class Auth(object):
@@ -10,38 +14,23 @@ class Auth(object):
         """Encodes parameters for a request suitable for including in a URL
         or POST body.  This method may also add new params to the request
         if required by the authentication scheme in use."""
-        raise NotImplementedError
+        raise NotImplementedError()
 
     def generate_headers(self):
         """Generates headers which should be added to the request if required
         by the authentication scheme in use."""
-        raise NotImplementedError
-
-
-class UserPassAuth(Auth):
-    """
-    Basic auth authentication using email/username and
-    password. Deprecated.
-    """
-    def __init__(self, username, password):
-        self.username = username
-        self.password = password
+        raise NotImplementedError()
 
-    def encode_params(self, base_url, method, params):
-        # We could consider automatically converting unicode to utf8 strings
-        # before encoding...
-        return urllib.urlencode(params)
-
-    def generate_headers(self):
-        return {"Authorization": "Basic " + encodestring("%s:%s" %(
-                self.username, self.password)).strip('\n')}
 
-class NoAuth(UserPassAuth):
+class NoAuth(Auth):
     """
     No authentication authenticator.
     """
     def __init__(self):
         pass
 
+    def encode_params(self, base_url, method, params):
+        return urllib_parse.urlencode(params)
+
     def generate_headers(self):
         return {}