import urllib
from base64 import encodestring
-class Auth:
+class Auth(object):
+ """
+ ABC for Authenticator objects.
+ """
+
def encode_params(self, base_url, method, params):
"""Encodes parameters for a request suitable for including in a URL
or POST body. This method may also add new params to the request
by the authentication scheme in use."""
raise NotImplementedError
-# An implementation using username and password.
+
class UserPassAuth(Auth):
+ """
+ Basic auth authentication using email/username and
+ password. Deprecated.
+ """
def __init__(self, username, password):
self.username = username
self.password = password
def generate_headers(self):
return {"Authorization": "Basic " + encodestring("%s:%s" %(
self.username, self.password)).strip('\n')}
+
+class NoAuth(UserPassAuth):
+ """
+ No authentication authenticator.
+ """
+ def __init__(self):
+ pass
+
+ def generate_headers(self):
+ return {}