# HG changeset patch # User Marcin Kasperski # Date 2019-06-22 06:26:23 # Node ID 4e2d69f2f13f30cbb644f34efad8c3a1339d9637 # Parent fb63e8874d90691761a58b930ad0a68e11fec36e Various py3 incompatibilities diff --git a/mercurial_keyring.py b/mercurial_keyring.py --- a/mercurial_keyring.py +++ b/mercurial_keyring.py @@ -224,7 +224,7 @@ class PasswordStore(object): err) return '' # Reverse recoding from next routine - if isinstance(password, unicode): + if isinstance(password, meu.pycompat.unicode): return encoding.tolocal(password.encode('utf-8')) return password @@ -251,11 +251,6 @@ password_store = PasswordStore() # Various utils ############################################################ -def _debug(ui, msg): - """Generic debug message""" - ui.debug("keyring: " + msg + "\n") - - class PwdCache(object): """Short term cache, used to preserve passwords if they are used twice during a command""" @@ -328,9 +323,9 @@ class HTTPPasswordHandler(object): ui = pwmgr.ui parsed_url, url_user, url_passwd = self.unpack_url(authuri) - base_url = str(parsed_url) - ui.debug(_('keyring: base url: %s, url user: %s, url pwd: %s\n') % - (base_url, url_user or '', url_passwd and '******' or '')) + base_url = bytes(parsed_url) + ui.debug(b'keyring: base url: %s, url user: %s, url pwd: %s\n' % + (base_url, url_user or b'', url_passwd and b'******' or b'')) # Extract username (or password) stored directly in url if url_user and url_passwd: @@ -371,7 +366,7 @@ class HTTPPasswordHandler(object): # Load from keyring. if actual_user: - ui.debug(_("keyring: looking for password (user %s, url %s)\n") % + ui.debug(b"keyring: looking for password (user %s, url %s)\n" % (actual_user, keyring_url)) keyring_pwd = password_store.get_http_password(keyring_url, actual_user) if keyring_pwd: @@ -389,10 +384,10 @@ class HTTPPasswordHandler(object): ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n")) ui.write(_("http authorization required\n")) - ui.status(_("realm: %s\n") % realm) + ui.status(_("realm: %s\n") % meu.pycompat.bytestr(realm)) ui.status(_("url: %s\n") % url) if user: - ui.write(_("user: %s (fixed in hgrc or url)\n", user)) + ui.write(_("user: %s (fixed in hgrc or url)\n") % user) else: user = ui.prompt(_("user:"), default=None) pwd = ui.getpass(_("password: ")) @@ -415,7 +410,7 @@ class HTTPPasswordHandler(object): if src != self.SRC_MEMCACHE: self.pwd_cache.store(realm, final_url, user, pwd) self._note_last_reply(realm, authuri, user, req) - _debug(ui, _("Password found in " + src)) + ui.debug("keyring: Password found in %s\n" % src) return user, pwd # Last resort: interactive prompt @@ -426,7 +421,7 @@ class HTTPPasswordHandler(object): # It is done only if username is permanently set. # Otherwise we won't be able to find the password so it # does not make much sense to preserve it - _debug(ui, _("Saving password for %s to keyring"), user) + ui.debug("keyring: Saving password for %s to keyring\n" % user) try: password_store.set_http_password(final_url, user, pwd) except Exception as e: @@ -440,7 +435,7 @@ class HTTPPasswordHandler(object): # Saving password to the memory cache self.pwd_cache.store(realm, final_url, user, pwd) self._note_last_reply(realm, authuri, user, req) - _debug(ui, _("Manually entered password")) + ui.debug("keyring: Manually entered password\n") return user, pwd def get_url_config(self, ui, parsed_url, user): @@ -452,10 +447,10 @@ class HTTPPasswordHandler(object): found. username and password can be None (if unset), if prefix is not found, url itself is returned. """ - base_url = str(parsed_url) + base_url = bytes(parsed_url) from mercurial.httpconnection import readauthforuri - _debug(ui, _("Checking for hgrc info about url %s, user %s") % (base_url, user)) + ui.debug(b"keyring: checking for hgrc info about url %s, user %s\n" % (base_url, user)) res = readauthforuri(ui, base_url, user) # If it user-less version not work, let's try with added username to handle # both config conventions @@ -479,8 +474,8 @@ class HTTPPasswordHandler(object): password_url = self.password_url(base_url, prefix) - _debug(ui, _("Password url: %s, user: %s, password: %s (prefix: %s)") % ( - password_url, username, '********' if password else '', prefix)) + ui.debug(b"keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n" % ( + password_url, username or b'', b'********' if password else b'', prefix or b'')) return username, password, password_url @@ -505,7 +500,8 @@ class HTTPPasswordHandler(object): if (self.last_reply['realm'] == realm) \ and (self.last_reply['authuri'] == authuri) \ and (self.last_reply['req'] == req): - _debug(ui, _("Working after bad authentication, cached passwords not used %s") % str(self.last_reply)) + ui.debug("keyring: Working after bad authentication, cached passwords not used %s\n" % + str(self.last_reply)) return True return False @@ -542,11 +538,12 @@ class HTTPPasswordHandler(object): where url is mercurial.util.url object already stripped of all those params. """ - import pdb; pdb.set_trace() + # In case of py3, util.url expects bytes + authuri = meu.pycompat.bytestr(authuri) # mercurial.util.url, rather handy url parser parsed_url = util.url(authuri) - parsed_url.query = '' + parsed_url.query = b'' parsed_url.fragment = None # Strip arguments to get actual remote repository url. # base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc,