X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/84d17de6402566ea12b3ddd97d3ad0b71756bbfd..dcece3a61cb23ca20f55e0f0b2572eb6b75e3941:/twitter/auth.py diff --git a/twitter/auth.py b/twitter/auth.py index a3a845d..77633ff 100644 --- a/twitter/auth.py +++ b/twitter/auth.py @@ -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): """