Comment out authentication handlers
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 340f7a0 · Browse files · 1 file·+15 added−160 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+15 added−160 removed
- other:+15 added−160 removed
Provenance
- Commit
94c587d- Tree
477d33d- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
340f7a0
1 file changed+15 added−160 removed
modified:requests/models.py+15 added-160 removed
92 unmodified lines93 #: :class:`Response <Response>` instance, containing94 #: content and metadata of HTTP Response, once :attr:`sent <send>`.95 self.response = Response()96 97- if isinstance(auth, (list, tuple)):98- auth = AuthObject(*auth)99- if not auth:100- auth = auth_manager.get_auth(self.url)97+ # if isinstance(auth, (list, tuple)):98+ # auth = AuthObject(*auth)99+ # if not auth:100+ # auth = auth_manager.get_auth(self.url)101 102 #: :class:`AuthObject` to attach to :class:`Request <Request>`.103 self.auth = auth104 32 unmodified lines137 138 if self.cookies is not None:139 _handlers.append(urllib2.HTTPCookieProcessor(self.cookies))140 141- if self.auth:142- if not isinstance(self.auth.handler,143- (urllib2.AbstractBasicAuthHandler,144- urllib2.AbstractDigestAuthHandler)):141+ # if self.auth:142+ # if not isinstance(self.auth.handler,143+ # (urllib2.AbstractBasicAuthHandler,144+ # urllib2.AbstractDigestAuthHandler)):145 146 # TODO: REMOVE THIS COMPLETELY147- auth_manager.add_password(148- self.auth.realm, self.url,149- self.auth.username,150- self.auth.password)147+ # auth_manager.add_password(148+ # self.auth.realm, self.url,149+ # self.auth.username,150+ # self.auth.password)151 152- self.auth.handler = self.auth.handler(auth_manager)153- auth_manager.add_auth(self.url, self.auth)152+ # self.auth.handler = self.auth.handler(auth_manager)153+ # auth_manager.add_auth(self.url, self.auth)154 155- _handlers.append(self.auth.handler)155+ # _handlers.append(self.auth.handler)156 157 if self.proxies:158 _handlers.append(urllib2.ProxyHandler(self.proxies))159 361 unmodified lines521 raise self.error522 523 524 525-class AuthManager(object):526- """Requests Authentication Manager."""527-528- def __new__(cls):529- singleton = cls.__dict__.get('__singleton__')530- if singleton is not None:531- return singleton532-533- cls.__singleton__ = singleton = object.__new__(cls)534-535- return singleton536-537-538- def __init__(self):539- self.passwd = {}540- self._auth = {}541-542-543- def __repr__(self):544- return '<AuthManager [%s]>' % (self.method)545-546-547- def add_auth(self, uri, auth):548- """Registers AuthObject to AuthManager."""549-550- uri = self.reduce_uri(uri, False)551-552- # try to make it an AuthObject553- if not isinstance(auth, AuthObject):554- try:555- auth = AuthObject(*auth)556- except TypeError:557- pass558-559- self._auth[uri] = auth560-561-562- def add_password(self, realm, uri, user, passwd):563- """Adds password to AuthManager."""564- # uri could be a single URI or a sequence565- if isinstance(uri, basestring):566- uri = [uri]567-568- reduced_uri = tuple([self.reduce_uri(u, False) for u in uri])569-570- if reduced_uri not in self.passwd:571- self.passwd[reduced_uri] = {}572- self.passwd[reduced_uri] = (user, passwd)573-574-575- def find_user_password(self, realm, authuri):576- for uris, authinfo in self.passwd.iteritems():577- reduced_authuri = self.reduce_uri(authuri, False)578- for uri in uris:579- if self.is_suburi(uri, reduced_authuri):580- return authinfo581-582- return (None, None)583-584-585- def get_auth(self, uri):586- (in_domain, in_path) = self.reduce_uri(uri, False)587-588- for domain, path, authority in (589- (i[0][0], i[0][1], i[1]) for i in self._auth.iteritems()590- ):591- if in_domain == domain:592- if path in in_path:593- return authority594-595-596- def reduce_uri(self, uri, default_port=True):597- """Accept authority or URI and extract only the authority and path."""598-599- # note HTTP URLs do not have a userinfo component600- parts = urllib2.urlparse.urlsplit(uri)601-602- if parts[1]:603- # URI604- scheme = parts[0]605- authority = parts[1]606- path = parts[2] or '/'607- else:608- # host or host:port609- scheme = None610- authority = uri611- path = '/'612-613- host, port = urllib2.splitport(authority)614-615- if default_port and port is None and scheme is not None:616- dport = {"http": 80,617- "https": 443,618- }.get(scheme)619- if dport is not None:620- authority = "%s:%d" % (host, dport)621-622- return authority, path623-624-625- def is_suburi(self, base, test):626- """Check if test is below base in a URI tree627-628- Both args must be URIs in reduced form.629- """630- if base == test:631- return True632- if base[0] != test[0]:633- return False634- common = urllib2.posixpath.commonprefix((base[1], test[1]))635- if len(common) == len(base[1]):636- return True637- return False638-639-640- def empty(self):641- self.passwd = {}642-643-644- def remove(self, uri, realm=None):645- # uri could be a single URI or a sequence646- if isinstance(uri, basestring):647- uri = [uri]648-649- for default_port in True, False:650- reduced_uri = tuple([self.reduce_uri(u, default_port) for u in uri])651- del self.passwd[reduced_uri][realm]652-653-654- def __contains__(self, uri):655- # uri could be a single URI or a sequence656- if isinstance(uri, basestring):657- uri = [uri]658-659- uri = tuple([self.reduce_uri(u, False) for u in uri])660-661- if uri in self.passwd:662- return True663-664- return False665-666-auth_manager = AuthManager()667-668-669-525 class AuthObject(object):526 """The :class:`AuthObject` is a simple HTTP Authentication token. When527 given to a Requests function, it enables Basic HTTP Authentication for that528 Request. You can also enable Authorization for domain realms with AutoAuth.25 unmodified lines