Read about our upcoming Code of Conduct on this issue

Commit 000d0a97 authored by Matt Harbison's avatar Matt Harbison
Browse files

Byteify the message argument to `ui_string()`

This is a thin wrapper around `mercurial.i18n._()` and as noted in the previous
commit, that is not meant to handle unicode.  We could fix that function to
convert internally before passing through, but I'm used to passing bytes to
these Mercurial internals, and every time I saw it I thought these needed to be
fixed.  Additionally, if translations are ever made, it should probably be done
in the same manner as core Mercurial (based on bytes).  The trailing arguments
are converted to bytes by `ui_string()` before interpolation, so this won't
introduce any incompatabilities.
parent 85ba8256007b
......@@ -233,7 +233,7 @@ class PasswordStore(object):
except Exception as err:
ui = uimod.ui()
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",
b"keyring: keyring backend doesn't seem to work, password can not be restored. Falling back to prompts. Error details: %s\n",
err))
return b''
# Reverse recoding from next routine
......@@ -258,7 +258,7 @@ class PasswordStore(object):
except Exception as err:
ui = uimod.ui()
ui.warn(meu.ui_string(
"keyring: keyring backend doesn't seem to work, password was not saved. Error details: %s\n",
b"keyring: keyring backend doesn't seem to work, password was not saved. Error details: %s\n",
err))
......@@ -342,7 +342,7 @@ class HTTPPasswordHandler(object):
parsed_url, url_user, url_passwd = self.unpack_url(authuri)
base_url = bytes(parsed_url)
ui.debug(meu.ui_string('keyring: base url: %s, url user: %s, url pwd: %s\n',
ui.debug(meu.ui_string(b'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
......@@ -384,7 +384,7 @@ class HTTPPasswordHandler(object):
# Load from keyring.
if actual_user:
ui.debug(meu.ui_string("keyring: looking for password (user %s, url %s)\n",
ui.debug(meu.ui_string(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:
......@@ -399,20 +399,20 @@ class HTTPPasswordHandler(object):
raise error.Abort(_(b'keyring: http authorization required but program used in non-interactive mode'))
if not user:
ui.status(meu.ui_string("keyring: username not specified in hgrc (or in url). Password will not be saved.\n"))
ui.status(meu.ui_string(b"keyring: username not specified in hgrc (or in url). Password will not be saved.\n"))
ui.write(meu.ui_string("http authorization required\n"))
ui.status(meu.ui_string("realm: %s\n",
ui.write(meu.ui_string(b"http authorization required\n"))
ui.status(meu.ui_string(b"realm: %s\n",
realm))
ui.status(meu.ui_string("url: %s\n",
ui.status(meu.ui_string(b"url: %s\n",
url))
if user:
ui.write(meu.ui_string("user: %s (fixed in hgrc or url)\n",
ui.write(meu.ui_string(b"user: %s (fixed in hgrc or url)\n",
user))
else:
user = ui.prompt(meu.ui_string("user:"),
user = ui.prompt(meu.ui_string(b"user:"),
default=None)
pwd = ui.getpass(meu.ui_string("password: "))
pwd = ui.getpass(meu.ui_string(b"password: "))
return user, pwd
def find_auth(self, pwmgr, realm, authuri, req):
......@@ -432,7 +432,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)
ui.debug(meu.ui_string("keyring: Password found in %s\n",
ui.debug(meu.ui_string(b"keyring: Password found in %s\n",
src))
return user, pwd
......@@ -444,7 +444,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
ui.debug(meu.ui_string("keyring: Saving password for %s to keyring\n",
ui.debug(meu.ui_string(b"keyring: Saving password for %s to keyring\n",
user))
try:
password_store.set_http_password(final_url, user, pwd)
......@@ -452,14 +452,14 @@ class HTTPPasswordHandler(object):
keyring = import_keyring()
if isinstance(e, keyring.errors.PasswordSetError):
ui.traceback()
ui.warn(meu.ui_string("warning: failed to save password in keyring\n"))
ui.warn(meu.ui_string(b"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(meu.ui_string("keyring: Manually entered password\n"))
ui.debug(meu.ui_string(b"keyring: Manually entered password\n"))
return user, pwd
def get_url_config(self, ui, parsed_url, user):
......@@ -472,7 +472,7 @@ class HTTPPasswordHandler(object):
is not found, url itself is returned.
"""
from mercurial.httpconnection import readauthforuri
ui.debug(meu.ui_string("keyring: checking for hgrc info about url %s, user %s\n",
ui.debug(meu.ui_string(b"keyring: checking for hgrc info about url %s, user %s\n",
parsed_url, user))
res = readauthforuri(ui, bytes(parsed_url), user)
......@@ -498,7 +498,7 @@ class HTTPPasswordHandler(object):
password_url = self.password_url(bytes(parsed_url), prefix)
ui.debug(meu.ui_string("keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n",
ui.debug(meu.ui_string(b"keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n",
password_url, username,
b'********' if password else b'',
prefix))
......@@ -527,7 +527,7 @@ class HTTPPasswordHandler(object):
and (self.last_reply['authuri'] == authuri) \
and (self.last_reply['req'] == req):
ui.debug(meu.ui_string(
"keyring: Working after bad authentication, cached passwords not used %s\n",
b"keyring: Working after bad authentication, cached passwords not used %s\n",
str(self.last_reply)))
return True
return False
......@@ -661,7 +661,7 @@ def try_smtp_login(ui, smtp_obj, username, password):
return True
except smtplib.SMTPException as inst:
if inst.smtp_code == 535:
ui.status(meu.ui_string("SMTP login failed: %s\n\n",
ui.status(meu.ui_string(b"SMTP login failed: %s\n\n",
inst.smtp_error))
return False
else:
......@@ -813,36 +813,36 @@ def cmd_keyring_check(ui, repo, *path_args, **opts): # pylint: disable=unused-
for path_arg in path_args]
else:
if not repo:
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"))
ui.status(meu.ui_string(b"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(meu.ui_string("keyring_check: no paths defined\n"))
ui.status(meu.ui_string(b"keyring_check: no paths defined\n"))
return
handler = HTTPPasswordHandler()
ui.status(meu.ui_string("keyring password save status:\n"))
ui.status(meu.ui_string(b"keyring password save status:\n"))
for name, url in paths:
if not is_http_path(url):
if path_args:
ui.status(meu.ui_string(" %s: non-http path (%s)\n",
ui.status(meu.ui_string(b" %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(meu.ui_string(
" %s: password available, source: %s, bound to user %s, url %s\n",
b" %s: password available, source: %s, bound to user %s, url %s\n",
name, source, user, final_url))
elif user:
ui.status(meu.ui_string(
" %s: password not available, once entered, will be bound to user %s, url %s\n",
b" %s: password not available, once entered, will be bound to user %s, url %s\n",
name, user, final_url))
else:
ui.status(meu.ui_string(
" %s: password not available, user unknown, url %s\n",
b" %s: password not available, user unknown, url %s\n",
name, final_url))
......@@ -864,7 +864,7 @@ def cmd_keyring_clear(ui, repo, path, **opts): # pylint: disable=unused-argumen
break
if not is_http_path(path_url):
ui.status(meu.ui_string(
"%s is not a http path (and %s can't be resolved as path alias)\n",
b"%s is not a http path (and %s can't be resolved as path alias)\n",
path, path_url))
return
......@@ -873,20 +873,20 @@ def cmd_keyring_clear(ui, repo, path, **opts): # pylint: disable=unused-argumen
user, pwd, source, final_url = handler.get_credentials(
make_passwordmgr(ui), path, path_url)
if not user:
ui.status(meu.ui_string("Username not configured for url %s\n",
ui.status(meu.ui_string(b"Username not configured for url %s\n",
final_url))
return
if not pwd:
ui.status(meu.ui_string("No password is saved for user %s, url %s\n",
ui.status(meu.ui_string(b"No password is saved for user %s, url %s\n",
user, final_url))
return
if source != handler.SRC_KEYRING:
ui.status(meu.ui_string("Password for user %s, url %s is saved in %s, not in keyring\n",
ui.status(meu.ui_string(b"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(meu.ui_string("Password removed for user %s, url %s\n",
ui.status(meu.ui_string(b"Password removed for user %s, url %s\n",
user, final_url))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment