Mercurial > hg
diff mercurial/url.py @ 29377:2c019aac6b99
url: extract password database from password manager
So far password manager was keeping authentication information so opening
new connection and creating new password manager made all saved authentication
information lost.
This commit separates password manager and password database to make it
possible to reuse saved authentication information.
This commit violates code checker because it adds add_password method (name
with underscore) to passwordmgr object to provide method required by urllib2.
author | liscju <piotr.listkiewicz@gmail.com> |
---|---|
date | Sun, 05 Jun 2016 23:36:23 +0200 |
parents | f1fe92c6c03c |
children | fea71f66ebff |
line wrap: on
line diff
--- a/mercurial/url.py Wed Jun 01 22:58:57 2016 +0200 +++ b/mercurial/url.py Sun Jun 05 23:36:23 2016 +0200 @@ -27,14 +27,16 @@ urlerr = util.urlerr urlreq = util.urlreq -class passwordmgr(urlreq.httppasswordmgrwithdefaultrealm): - def __init__(self, ui): - urlreq.httppasswordmgrwithdefaultrealm.__init__(self) +class passwordmgr(object): + def __init__(self, ui, passwddb): self.ui = ui + self.passwddb = passwddb + + def add_password(self, realm, uri, user, passwd): + return self.passwddb.add_password(realm, uri, user, passwd) def find_user_password(self, realm, authuri): - authinfo = urlreq.httppasswordmgrwithdefaultrealm.find_user_password( - self, realm, authuri) + authinfo = self.passwddb.find_user_password(realm, authuri) user, passwd = authinfo if user and passwd: self._writedebug(user, passwd) @@ -64,7 +66,7 @@ if not passwd: passwd = self.ui.getpass() - self.add_password(realm, authuri, user, passwd) + self.passwddb.add_password(realm, authuri, user, passwd) self._writedebug(user, passwd) return (user, passwd) @@ -73,8 +75,7 @@ self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set')) def find_stored_password(self, authuri): - return urlreq.httppasswordmgrwithdefaultrealm.find_user_password( - self, None, authuri) + return self.passwddb.find_user_password(None, authuri) class proxyhandler(urlreq.proxyhandler): def __init__(self, ui): @@ -363,7 +364,8 @@ keepalive.KeepAliveHandler.__init__(self) urlreq.httpshandler.__init__(self) self.ui = ui - self.pwmgr = passwordmgr(self.ui) + self.pwmgr = passwordmgr(self.ui, + urlreq.httppasswordmgrwithdefaultrealm()) def _start_transaction(self, h, req): _generic_start_transaction(self, h, req) @@ -477,7 +479,11 @@ ''' # experimental config: ui.usehttp2 if ui.configbool('ui', 'usehttp2', False): - handlers = [httpconnectionmod.http2handler(ui, passwordmgr(ui))] + handlers = [ + httpconnectionmod.http2handler( + ui, + passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm())) + ] else: handlers = [httphandler()] if has_https: @@ -485,7 +491,7 @@ handlers.append(proxyhandler(ui)) - passmgr = passwordmgr(ui) + passmgr = passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()) if authinfo is not None: passmgr.add_password(*authinfo) user, passwd = authinfo[2:4]