Mercurial > public > mercurial-scm > hg
comparison mercurial/windows.py @ 47789: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 | bb917eea1605 |
children | 4162f6b40f2c |
comparison
equal
deleted
inserted
replaced
47788:48f07adbda98 | 47789:064cd182555f |
---|---|
198 """Prompt for password with echo off, using Windows getch(). | 198 """Prompt for password with echo off, using Windows getch(). |
199 | 199 |
200 This shouldn't be called directly- use ``ui.getpass()`` instead, which | 200 This shouldn't be called directly- use ``ui.getpass()`` instead, which |
201 checks if the session is interactive first. | 201 checks if the session is interactive first. |
202 """ | 202 """ |
203 pw = "" | 203 pw = u"" |
204 while True: | 204 while True: |
205 c = msvcrt.getwch() # pytype: disable=module-attr | 205 c = msvcrt.getwch() # pytype: disable=module-attr |
206 if c == '\r' or c == '\n': | 206 if c == u'\r' or c == u'\n': |
207 break | 207 break |
208 if c == '\003': | 208 if c == u'\003': |
209 raise KeyboardInterrupt | 209 raise KeyboardInterrupt |
210 if c == '\b': | 210 if c == u'\b': |
211 pw = pw[:-1] | 211 pw = pw[:-1] |
212 else: | 212 else: |
213 pw = pw + c | 213 pw = pw + c |
214 msvcrt.putwch('\r') # pytype: disable=module-attr | 214 msvcrt.putwch(u'\r') # pytype: disable=module-attr |
215 msvcrt.putwch('\n') # pytype: disable=module-attr | 215 msvcrt.putwch(u'\n') # pytype: disable=module-attr |
216 return encoding.strtolocal(pw) | 216 return encoding.unitolocal(pw) |
217 | 217 |
218 | 218 |
219 class winstdout(object): | 219 class winstdout(object): |
220 """Some files on Windows misbehave. | 220 """Some files on Windows misbehave. |
221 | 221 |