]>
jfr.im git - z_archive/twitter.git/blob - twitter/auth.py
2 from base64
import encodestring
5 def encode_params(self
, base_url
, method
, params
):
6 """Encodes parameters for a request suitable for including in a URL
7 or POST body. This method may also add new params to the request
8 if required by the authentication scheme in use."""
9 raise NotImplementedError
11 def generate_headers(self
):
12 """Generates headers which should be added to the request if required
13 by the authentication scheme in use."""
14 raise NotImplementedError
16 # An implementation using username and password.
17 class UserPassAuth(Auth
):
18 def __init__(self
, username
, password
):
19 self
.username
= username
20 self
.password
= password
22 def encode_params(self
, base_url
, method
, params
):
23 # We could consider automatically converting unicode to utf8 strings
25 return urllib
.urlencode(params
)
27 def generate_headers(self
):
28 return {"Authorization": "Basic " + encodestring("%s:%s" %(
29 self
.username
, self
.password
)).strip('\n')}
31 class NoAuth(UserPassAuth
):
35 def generate_headers(self
):