##// END OF EJS Templates
util: avoid echoing the password to the console on Windows py3 (issue6446)...
Matt Harbison -
r47949:5b351317 stable
parent child Browse files
Show More
@@ -381,6 +381,10 b' def getfstype(dirpath):'
381 return getattr(osutil, 'getfstype', lambda x: None)(dirpath)
381 return getattr(osutil, 'getfstype', lambda x: None)(dirpath)
382
382
383
383
384 def get_password():
385 return encoding.strtolocal(getpass.getpass(''))
386
387
384 def setbinary(fd):
388 def setbinary(fd):
385 pass
389 pass
386
390
@@ -11,7 +11,6 b' import collections'
11 import contextlib
11 import contextlib
12 import datetime
12 import datetime
13 import errno
13 import errno
14 import getpass
15 import inspect
14 import inspect
16 import os
15 import os
17 import re
16 import re
@@ -1779,7 +1778,7 b' class ui(object):'
1779 raise EOFError
1778 raise EOFError
1780 return l.rstrip(b'\n')
1779 return l.rstrip(b'\n')
1781 else:
1780 else:
1782 return encoding.strtolocal(getpass.getpass(''))
1781 return util.get_password()
1783 except EOFError:
1782 except EOFError:
1784 raise error.ResponseExpected()
1783 raise error.ResponseExpected()
1785
1784
@@ -106,6 +106,7 b' copymode = platform.copymode'
106 expandglobs = platform.expandglobs
106 expandglobs = platform.expandglobs
107 getfsmountpoint = platform.getfsmountpoint
107 getfsmountpoint = platform.getfsmountpoint
108 getfstype = platform.getfstype
108 getfstype = platform.getfstype
109 get_password = platform.get_password
109 groupmembers = platform.groupmembers
110 groupmembers = platform.groupmembers
110 groupname = platform.groupname
111 groupname = platform.groupname
111 isexec = platform.isexec
112 isexec = platform.isexec
@@ -194,6 +194,28 b' def _isatty(fp):'
194 return False
194 return False
195
195
196
196
197 def get_password():
198 """Prompt for password with echo off, using Windows getch().
199
200 This shouldn't be called directly- use ``ui.getpass()`` instead, which
201 checks if the session is interactive first.
202 """
203 pw = ""
204 while True:
205 c = msvcrt.getwch()
206 if c == '\r' or c == '\n':
207 break
208 if c == '\003':
209 raise KeyboardInterrupt
210 if c == '\b':
211 pw = pw[:-1]
212 else:
213 pw = pw + c
214 msvcrt.putwch('\r')
215 msvcrt.putwch('\n')
216 return encoding.strtolocal(pw)
217
218
197 class winstdout(object):
219 class winstdout(object):
198 """Some files on Windows misbehave.
220 """Some files on Windows misbehave.
199
221
General Comments 0
You need to be logged in to leave comments. Login now