Patchwork [STABLE] i18n: show the non-ASCII password prompt text correctly

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 25, 2013, 3:38 p.m.
Message ID <be207d9b7e4bc222f4ba.1366904321@juju>
Download mbox | patch
Permalink /patch/1479/
State Accepted
Commit be207d9b7e4bc222f4ba72ad9a266df83d939ca4
Headers show

Comments

Katsunori FUJIWARA - April 25, 2013, 3:38 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1366890529 -32400
#      Thu Apr 25 20:48:49 2013 +0900
# Branch stable
# Node ID be207d9b7e4bc222f4ba72ad9a266df83d939ca4
# Parent  70675d77fd4a78d3e57723550d9f3031345d38e4
i18n: show the non-ASCII password prompt text correctly

Before this patch, the prompt text for asking password is directly
passed to "getpass.getpass()" of Python standard library.

In "getpass.getpass()" implementation on Windows environment, the
prompt text is split into byte sequence and "msvcrt.putch()" is
applied on each bytes in it. This splitting causes non-ASCII prompt
text to be broken.

This patch shows the prompt text for asking password on "ui.getpass()"
side, and invokes "getpass.getpass()" with empty prompt text. This
prevents non-ASCII prompt text from being broken in
"getpass.getpass()" implementation.

This patch also sets "ui.prompt" label to prompt text to follow
"ui.prompt()" style.
Matt Mackall - April 25, 2013, 3:40 p.m.
On Fri, 2013-04-26 at 00:38 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1366890529 -32400
> #      Thu Apr 25 20:48:49 2013 +0900
> # Branch stable
> # Node ID be207d9b7e4bc222f4ba72ad9a266df83d939ca4
> # Parent  70675d77fd4a78d3e57723550d9f3031345d38e4
> i18n: show the non-ASCII password prompt text correctly
> 
> Before this patch, the prompt text for asking password is directly
> passed to "getpass.getpass()" of Python standard library.
> 
> In "getpass.getpass()" implementation on Windows environment, the
> prompt text is split into byte sequence and "msvcrt.putch()" is
> applied on each bytes in it. This splitting causes non-ASCII prompt
> text to be broken.
> 
> This patch shows the prompt text for asking password on "ui.getpass()"
> side, and invokes "getpass.getpass()" with empty prompt text. This
> prevents non-ASCII prompt text from being broken in
> "getpass.getpass()" implementation.
> 
> This patch also sets "ui.prompt" label to prompt text to follow
> "ui.prompt()" style.

Looks good, queued for stable.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -663,7 +663,8 @@ 
         if not self.interactive():
             return default
         try:
-            return getpass.getpass(prompt or _('password: '))
+            self.write(self.label(prompt or _('password: '), 'ui.prompt'))
+            return getpass.getpass('')
         except EOFError:
             raise util.Abort(_('response expected'))
     def status(self, *msg, **opts):