Skip to content
Myr

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

1 file+15 added−160 removed

modified:requests/models.py+15 added-160 removed
92 unmodified lines
93 #: :class:`Response <Response>` instance, containing94 #: content and metadata of HTTP Response, once :attr:`sent <send>`.95 self.response = Response()9697 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)101102 #: :class:`AuthObject` to attach to :class:`Request <Request>`.103 self.auth = auth104
32 unmodified lines
137138 if self.cookies is not None:139 _handlers.append(urllib2.HTTPCookieProcessor(self.cookies))140141 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)):145146 # 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)151152 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)154155 _handlers.append(self.auth.handler)155 # _handlers.append(self.auth.handler)156157 if self.proxies:158 _handlers.append(urllib2.ProxyHandler(self.proxies))159
361 unmodified lines
521 raise self.error522523524525class AuthManager(object):526 """Requests Authentication Manager."""527528 def __new__(cls):529 singleton = cls.__dict__.get('__singleton__')530 if singleton is not None:531 return singleton532533 cls.__singleton__ = singleton = object.__new__(cls)534535 return singleton536537538 def __init__(self):539 self.passwd = {}540 self._auth = {}541542543 def __repr__(self):544 return '<AuthManager [%s]>' % (self.method)545546547 def add_auth(self, uri, auth):548 """Registers AuthObject to AuthManager."""549550 uri = self.reduce_uri(uri, False)551552 # try to make it an AuthObject553 if not isinstance(auth, AuthObject):554 try:555 auth = AuthObject(*auth)556 except TypeError:557 pass558559 self._auth[uri] = auth560561562 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]567568 reduced_uri = tuple([self.reduce_uri(u, False) for u in uri])569570 if reduced_uri not in self.passwd:571 self.passwd[reduced_uri] = {}572 self.passwd[reduced_uri] = (user, passwd)573574575 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 authinfo581582 return (None, None)583584585 def get_auth(self, uri):586 (in_domain, in_path) = self.reduce_uri(uri, False)587588 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 authority594595596 def reduce_uri(self, uri, default_port=True):597 """Accept authority or URI and extract only the authority and path."""598599 # note HTTP URLs do not have a userinfo component600 parts = urllib2.urlparse.urlsplit(uri)601602 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 = '/'612613 host, port = urllib2.splitport(authority)614615 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)621622 return authority, path623624625 def is_suburi(self, base, test):626 """Check if test is below base in a URI tree627628 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 False638639640 def empty(self):641 self.passwd = {}642643644 def remove(self, uri, realm=None):645 # uri could be a single URI or a sequence646 if isinstance(uri, basestring):647 uri = [uri]648649 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]652653654 def __contains__(self, uri):655 # uri could be a single URI or a sequence656 if isinstance(uri, basestring):657 uri = [uri]658659 uri = tuple([self.reduce_uri(u, False) for u in uri])660661 if uri in self.passwd:662 return True663664 return False665666auth_manager = AuthManager()667668669525class 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