]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/auth.py
Further simplification in progress.
[z_archive/twitter.git] / twitter / auth.py
index a3a845d14ec9bea9f9400ae3d3ef4fd24fe95b25..77633fff6eca0b166a72b1c0ea8af75628b16bbc 100644 (file)
@@ -1,9 +1,9 @@
 try:
     import urllib.parse as urllib_parse
+    from base64 import encodebytes
 except ImportError:
     import urllib as urllib_parse
-
-from base64 import encodestring
+    from base64 import encodestring as encodebytes
 
 class Auth(object):
     """
@@ -21,6 +21,25 @@ class Auth(object):
         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
+
+    def encode_params(self, base_url, method, params):
+        # We could consider automatically converting unicode to utf8 strings
+        # before encoding...
+        return urllib_parse.urlencode(params)
+
+    def generate_headers(self):
+        return {b"Authorization": b"Basic " + encodebytes(
+                ("%s:%s" %(self.username, self.password))
+                .encode('utf8')).strip(b'\n')
+                }
 
 class NoAuth(Auth):
     """