changeset 13372:5bced0d28a39

url: return the matched authentication group name from readauthforuri() Internally, the group name is only used in debug statements, but readauthforuri can be also used externally to determine which group will be matched for a given URL.
author Steve Borho <steve@borho.org>
date Sun, 13 Feb 2011 12:19:58 -0600
parents c691cfdc6b4d
children 900a92862a7b
files mercurial/url.py
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/url.py	Sat Feb 12 21:59:43 2011 -0600
+++ b/mercurial/url.py	Sun Feb 13 12:19:58 2011 -0600
@@ -88,7 +88,7 @@
     scheme, hostpath = uri.split('://', 1)
     bestlen = 0
     bestauth = None
-    for auth in config.itervalues():
+    for group, auth in config.iteritems():
         prefix = auth.get('prefix')
         if not prefix:
             continue
@@ -100,7 +100,7 @@
         if (prefix == '*' or hostpath.startswith(prefix)) and \
             len(prefix) > bestlen and scheme in schemes:
             bestlen = len(prefix)
-            bestauth = auth
+            bestauth = group, auth
     return bestauth
 
 _safe = ('abcdefghijklmnopqrstuvwxyz'
@@ -155,9 +155,11 @@
             return (user, passwd)
 
         if not user:
-            auth = self.readauthtoken(authuri)
-            if auth:
+            res = readauthforuri(self.ui, authuri)
+            if res:
+                group, auth = res
                 user, passwd = auth.get('username'), auth.get('password')
+                self.ui.debug("using auth.%s.* for authentication\n" % group)
         if not user or not passwd:
             if not self.ui.interactive():
                 raise util.Abort(_('http authorization required'))
@@ -180,9 +182,6 @@
         msg = _('http auth: user %s, password %s\n')
         self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set'))
 
-    def readauthtoken(self, uri):
-        return readauthforuri(self.ui, uri)
-
 class proxyhandler(urllib2.ProxyHandler):
     def __init__(self, ui):
         proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
@@ -624,7 +623,13 @@
             return keepalive.KeepAliveHandler._start_transaction(self, h, req)
 
         def https_open(self, req):
-            self.auth = self.pwmgr.readauthtoken(req.get_full_url())
+            res = readauthforuri(self.ui, req.get_full_url())
+            if res:
+                group, auth = res
+                self.auth = auth
+                self.ui.debug("using auth.%s.* for authentication\n" % group)
+            else:
+                self.auth = None
             return self.do_open(self._makeconnection, req)
 
         def _makeconnection(self, host, port=None, *args, **kwargs):