aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-04-21 10:40:58 +0000
committerThomas Wouters <thomas@python.org>2006-04-21 10:40:58 +0000
commit49fd7fa4431da299196d74087df4a04f99f9c46f (patch)
tree35ace5fe78d3d52c7a9ab356ab9f6dbf8d4b71f4 /Lib/getpass.py
parentMerge trunk up to 43069, putting re.py back and hopefully making the branch (diff)
downloadcpython-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.gz
cpython-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.bz2
cpython-49fd7fa4431da299196d74087df4a04f99f9c46f.zip
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described here (it's not a Py3K issue, just something Py3K discovers): http://mail.python.org/pipermail/python-dev/2006-April/064051.html Hye-Shik Chang promised to look for a fix, so no need to fix it here. The tests that are expected to break are: test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecs test_multibytecodec This merge fixes an actual test failure (test_weakref) in this branch, though, so I believe merging is the right thing to do anyway.
Diffstat (limited to 'Lib/getpass.py')
-rw-r--r--Lib/getpass.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/Lib/getpass.py b/Lib/getpass.py
index a30d3a15416..8204a479f61 100644
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -15,11 +15,14 @@ import sys
__all__ = ["getpass","getuser"]
-def unix_getpass(prompt='Password: '):
+def unix_getpass(prompt='Password: ', stream=None):
"""Prompt for a password, with echo turned off.
+ The prompt is written on stream, by default stdout.
Restore terminal settings at end.
"""
+ if stream is None:
+ stream = sys.stdout
try:
fd = sys.stdin.fileno()
@@ -32,18 +35,18 @@ def unix_getpass(prompt='Password: '):
new[3] = new[3] & ~termios.ECHO # 3 == 'lflags'
try:
termios.tcsetattr(fd, termios.TCSADRAIN, new)
- passwd = _raw_input(prompt)
+ passwd = _raw_input(prompt, stream)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
- sys.stdout.write('\n')
+ stream.write('\n')
return passwd
-def win_getpass(prompt='Password: '):
+def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
- return default_getpass(prompt)
+ return default_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c)
@@ -63,16 +66,18 @@ def win_getpass(prompt='Password: '):
return pw
-def default_getpass(prompt='Password: '):
- print "Warning: Problem with getpass. Passwords may be echoed."
- return _raw_input(prompt)
+def default_getpass(prompt='Password: ', stream=None):
+ print >>sys.stderr, "Warning: Problem with getpass. Passwords may be echoed."
+ return _raw_input(prompt, stream)
-def _raw_input(prompt=""):
+def _raw_input(prompt="", stream=None):
# This doesn't save the string in the GNU readline history.
+ if stream is None:
+ stream = sys.stdout
prompt = str(prompt)
if prompt:
- sys.stdout.write(prompt)
+ stream.write(prompt)
line = sys.stdin.readline()
if not line:
raise EOFError