From: Kenneth Reitz Date: Fri, 15 Apr 2011 21:18:58 +0000 (-0400) Subject: Fixes #20. X-Git-Tag: v0.3.2~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2814664e91d9a7516f0f5f156fb482b9109a8b5b;p=services%2Fpython-requests.git Fixes #20. --- diff --git a/requests/core.py b/requests/core.py index 4ec6824..2a4cc09 100644 --- a/requests/core.py +++ b/requests/core.py @@ -286,6 +286,14 @@ class AuthManager(object): """Registers AuthObject to AuthManager.""" uri = self.reduce_uri(uri, False) + + # try to make it an AuthObject + if not isinstance(auth, AuthObject): + try: + auth = AuthObject(*auth) + except TypeError: + pass + self._auth[uri] = auth def add_password(self, realm, uri, user, passwd): @@ -312,8 +320,14 @@ class AuthManager(object): def get_auth(self, uri): - uri = self.reduce_uri(uri, False) - return self._auth.get(uri, None) + (in_domain, in_path) = self.reduce_uri(uri, False) + + for domain, path, authority in ( + (i[0][0], i[0][1], i[1]) for i in self._auth.iteritems() + ): + if in_domain == domain: + if path in in_path: + return authority def reduce_uri(self, uri, default_port=True): @@ -337,6 +351,7 @@ class AuthManager(object): }.get(scheme) if dport is not None: authority = "%s:%d" % (host, dport) + return authority, path