diff --git a/mercurial_keyring.py b/mercurial_keyring.py --- a/mercurial_keyring.py +++ b/mercurial_keyring.py @@ -220,8 +220,8 @@ class PasswordStore(object): password = keyring.get_password(KEYRING_SERVICE, pwdkey) except Exception as err: ui = uimod.ui() - ui.warn(_("keyring: keyring backend doesn't seem to work, password can not be restored. Falling back to prompts. Error details: %s\n") % - err) + ui.warn(meu.ui_string("keyring: keyring backend doesn't seem to work, password can not be restored. Falling back to prompts. Error details: %s\n", + err)) return '' # Reverse recoding from next routine if isinstance(password, meu.pycompat.unicode): @@ -240,8 +240,9 @@ class PasswordStore(object): KEYRING_SERVICE, pwdkey, password) except Exception as err: ui = uimod.ui() - ui.warn(_("keyring: keyring backend doesn't seem to work, password was not saved. Error details: %s\n") % - err) + ui.warn(meu.ui_string( + "keyring: keyring backend doesn't seem to work, password was not saved. Error details: %s\n", + err)) password_store = PasswordStore() @@ -324,8 +325,8 @@ class HTTPPasswordHandler(object): parsed_url, url_user, url_passwd = self.unpack_url(authuri) 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'')) + ui.debug(meu.ui_string('keyring: base url: %s, url user: %s, url pwd: %s\n', + base_url, url_user, url_passwd and b'******' or b'')) # Extract username (or password) stored directly in url if url_user and url_passwd: @@ -366,8 +367,8 @@ class HTTPPasswordHandler(object): # Load from keyring. if actual_user: - ui.debug(b"keyring: looking for password (user %s, url %s)\n" % - (actual_user, keyring_url)) + ui.debug(meu.ui_string("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: return actual_user, keyring_pwd, self.SRC_KEYRING, keyring_url @@ -381,16 +382,20 @@ class HTTPPasswordHandler(object): raise error.Abort(_('keyring: http authorization required but program used in non-interactive mode')) if not user: - ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n")) + ui.status(meu.ui_string("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") % meu.pycompat.bytestr(realm)) - ui.status(_("url: %s\n") % url) + ui.write(meu.ui_string("http authorization required\n")) + ui.status(meu.ui_string("realm: %s\n", + realm)) + ui.status(meu.ui_string("url: %s\n", + url)) if user: - ui.write(_("user: %s (fixed in hgrc or url)\n") % user) + ui.write(meu.ui_string("user: %s (fixed in hgrc or url)\n", + user)) else: - user = ui.prompt(_("user:"), default=None) - pwd = ui.getpass(_("password: ")) + user = ui.prompt(meu.ui_string("user:"), + default=None) + pwd = ui.getpass(meu.ui_string("password: ")) return user, pwd def find_auth(self, pwmgr, realm, authuri, req): @@ -410,7 +415,8 @@ 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) - ui.debug("keyring: Password found in %s\n" % src) + ui.debug(meu.ui_string("keyring: Password found in %s\n", + src)) return user, pwd # Last resort: interactive prompt @@ -421,21 +427,22 @@ 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 - ui.debug("keyring: Saving password for %s to keyring\n" % user) + ui.debug(meu.ui_string("keyring: Saving password for %s to keyring\n", + user)) try: password_store.set_http_password(final_url, user, pwd) except Exception as e: keyring = import_keyring() if isinstance(e, keyring.errors.PasswordSetError): ui.traceback() - ui.warn(_("warning: failed to save password in keyring\n")) + ui.warn(meu.ui_string("warning: failed to save password in keyring\n")) else: raise e # Saving password to the memory cache self.pwd_cache.store(realm, final_url, user, pwd) self._note_last_reply(realm, authuri, user, req) - ui.debug("keyring: Manually entered password\n") + ui.debug(meu.ui_string("keyring: Manually entered password\n")) return user, pwd def get_url_config(self, ui, parsed_url, user): @@ -448,7 +455,8 @@ class HTTPPasswordHandler(object): is not found, url itself is returned. """ from mercurial.httpconnection import readauthforuri - ui.debug(b"keyring: checking for hgrc info about url %s, user %s\n" % (parsed_url, user)) + ui.debug(meu.ui_string("keyring: checking for hgrc info about url %s, user %s\n", + parsed_url, user)) res = readauthforuri(ui, str(parsed_url), user) # If it user-less version not work, let's try with added username to handle # both config conventions @@ -472,8 +480,10 @@ class HTTPPasswordHandler(object): password_url = self.password_url(str(parsed_url), 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'')) + ui.debug(meu.ui_string("keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n", + password_url, username, + b'********' if password else b'', + prefix)) return username, password, password_url @@ -498,8 +508,9 @@ class HTTPPasswordHandler(object): if (self.last_reply['realm'] == realm) \ and (self.last_reply['authuri'] == authuri) \ and (self.last_reply['req'] == req): - ui.debug("keyring: Working after bad authentication, cached passwords not used %s\n" % - str(self.last_reply)) + ui.debug(meu.ui_string( + "keyring: Working after bad authentication, cached passwords not used %s\n", + str(self.last_reply))) return True return False @@ -632,8 +643,8 @@ def try_smtp_login(ui, smtp_obj, usernam return True except smtplib.SMTPException as inst: if inst.smtp_code == 535: - ui.status(_("SMTP login failed: %s\n\n") % - inst.smtp_error) + ui.status(meu.ui_string("SMTP login failed: %s\n\n", + inst.smtp_error)) return False else: raise error.Abort(inst) @@ -784,34 +795,37 @@ def cmd_keyring_check(ui, repo, *path_ar for path_arg in path_args] else: if not repo: - ui.status(_("Url to check not specified. Either run ``hg keyring_check https://...``, or run the command inside some repository (to test all defined paths).\n")) + ui.status(meu.ui_string("Url to check not specified. Either run ``hg keyring_check https://...``, or run the command inside some repository (to test all defined paths).\n")) return paths = [(name, url) for name, url in defined_paths] if not paths: - ui.status(_("keyring_check: no paths defined\n")) + ui.status(meu.ui_string("keyring_check: no paths defined\n")) return handler = HTTPPasswordHandler() - ui.status(_("keyring password save status:\n")) + ui.status(meu.ui_string("keyring password save status:\n")) for name, url in paths: if not is_http_path(url): if path_args: - ui.status(_(" %s: non-http path (%s)\n") % - (name, url)) + ui.status(meu.ui_string(" %s: non-http path (%s)\n", + name, url)) continue user, pwd, source, final_url = handler.get_credentials( make_passwordmgr(ui), name, url) if pwd: - ui.status(_(" %s: password available, source: %s, bound to user %s, url %s\n") % - (name, source, user, final_url)) + ui.status(meu.ui_string( + " %s: password available, source: %s, bound to user %s, url %s\n", + name, source, user, final_url)) elif user: - ui.status(_(" %s: password not available, once entered, will be bound to user %s, url %s\n") % - (name, user, final_url)) + ui.status(meu.ui_string( + " %s: password not available, once entered, will be bound to user %s, url %s\n", + name, user, final_url)) else: - ui.status(_(" %s: password not available, user unknown, url %s\n") % - (name, final_url)) + ui.status(meu.ui_string( + " %s: password not available, user unknown, url %s\n", + name, final_url)) @command(b'keyring_clear', @@ -831,8 +845,9 @@ def cmd_keyring_clear(ui, repo, path, ** path_url = url break if not is_http_path(path_url): - ui.status(_("%s is not a http path (and %s can't be resolved as path alias)\n") % - (path, path_url)) + ui.status(meu.ui_string( + "%s is not a http path (and %s can't be resolved as path alias)\n", + path, path_url)) return handler = HTTPPasswordHandler() @@ -840,21 +855,21 @@ def cmd_keyring_clear(ui, repo, path, ** user, pwd, source, final_url = handler.get_credentials( make_passwordmgr(ui), path, path_url) if not user: - ui.status(_("Username not configured for url %s\n") % - final_url) + ui.status(meu.ui_string("Username not configured for url %s\n", + final_url)) return if not pwd: - ui.status(_("No password is saved for user %s, url %s\n") % - (user, final_url)) + ui.status(meu.ui_string("No password is saved for user %s, url %s\n", + user, final_url)) return if source != handler.SRC_KEYRING: - ui.status(_("Password for user %s, url %s is saved in %s, not in keyring\n") % - (user, final_url, source)) + ui.status(meu.ui_string("Password for user %s, url %s is saved in %s, not in keyring\n", + user, final_url, source)) password_store.clear_http_password(final_url, user) - ui.status(_("Password removed for user %s, url %s\n") % - (user, final_url)) + ui.status(meu.ui_string("Password removed for user %s, url %s\n", + user, final_url)) buglink = 'https://bitbucket.org/Mekk/mercurial_keyring/issues'