]> jfr.im git - z_archive/twitter.git/blob - twitter/auth.py
import fix for py2
[z_archive/twitter.git] / twitter / auth.py
1 try:
2 import urllib.parse as urllib_parse
3 except ImportError:
4 import urllib as urllib_parse
5
6 from base64 import encodestring
7
8 class Auth(object):
9 """
10 ABC for Authenticator objects.
11 """
12
13 def encode_params(self, base_url, method, params):
14 """Encodes parameters for a request suitable for including in a URL
15 or POST body. This method may also add new params to the request
16 if required by the authentication scheme in use."""
17 raise NotImplementedError()
18
19 def generate_headers(self):
20 """Generates headers which should be added to the request if required
21 by the authentication scheme in use."""
22 raise NotImplementedError()
23
24
25 class NoAuth(Auth):
26 """
27 No authentication authenticator.
28 """
29 def __init__(self):
30 pass
31
32 def encode_params(self, base_url, method, params):
33 return urllib_parse.urlencode(params)
34
35 def generate_headers(self):
36 return {}