Mercurial > hg-stable
changeset 47788:064cd182555f stable
windows: avoid a bytes vs unicode crash reading passwords on py2
This broke in 5b3513177f2b. Specifically, after typing in the password on py2,
it would crash with:
TypeError: putwch() argument 1 must be cannot convert raw buffers, not str
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 02 Aug 2021 10:51:19 -0400 |
parents | 48f07adbda98 |
children | a11520e66ade |
files | mercurial/windows.py |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/windows.py Sun Aug 01 10:54:03 2021 -0400 +++ b/mercurial/windows.py Mon Aug 02 10:51:19 2021 -0400 @@ -200,20 +200,20 @@ This shouldn't be called directly- use ``ui.getpass()`` instead, which checks if the session is interactive first. """ - pw = "" + pw = u"" while True: c = msvcrt.getwch() # pytype: disable=module-attr - if c == '\r' or c == '\n': + if c == u'\r' or c == u'\n': break - if c == '\003': + if c == u'\003': raise KeyboardInterrupt - if c == '\b': + if c == u'\b': pw = pw[:-1] else: pw = pw + c - msvcrt.putwch('\r') # pytype: disable=module-attr - msvcrt.putwch('\n') # pytype: disable=module-attr - return encoding.strtolocal(pw) + msvcrt.putwch(u'\r') # pytype: disable=module-attr + msvcrt.putwch(u'\n') # pytype: disable=module-attr + return encoding.unitolocal(pw) class winstdout(object):