Skip to content
Myr

keep auth DRY

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent f8cf713 · Browse files · 1 file+8 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−4 removed

  • other:+8 added−4 removed

1 file+8 added−4 removed

modified:requests/auth.py+8 added-4 removed
14 unmodified lines
1516from .utils import randombytes, parse_dict_header17181920def _basic_auth_str(username, password):21 """Returns a Basic Auth string."""22 return 'Basic %s' % b64encode('%s:%s' % (username, password))232425class AuthBase(object):26 """Base class that all auth implementations derive from"""2728 def __call__(self, r):
6 unmodified lines
35 self.username = str(username)36 self.password = str(password)3738 def __call__(self, r):33 auth_s = b64encode('%s:%s' % (self.username, self.password))34 r.headers['Authorization'] = ('Basic %s' % auth_s)39 r.headers['Authorization'] = _basic_auth_str(self.username, self.password)40 return r414243class HTTPProxyAuth(HTTPBasicAuth):44 """Attaches HTTP Proxy Authenetication to a given Request object."""45 def __call__(self, r):41 auth_s = b64encode('%s:%s' % (self.username, self.password))42 r.headers['Proxy-Authorization'] = ('Basic %s' % auth_s)46 r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)47 return r484950class HTTPDigestAuth(AuthBase):
86 unmodified lines