Steffen Daode Nurpmeso <sdao...@googlemail.com> added the comment:
This new patch (11466.2.patch) also includes the #11236 patch,
because if ^C would work as expected then that would not close the
fd either.
It's identical to the first patch beside that.
----------
Added file: http://bugs.python.org/file21081/11466.2.patch
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11466>
_______________________________________
diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -62,20 +62,30 @@
try:
old = termios.tcgetattr(fd) # a copy to save
new = old[:]
- new[3] &= ~(termios.ECHO|termios.ISIG) # 3 == 'lflags'
+ new[3] &= ~termios.ECHO # 3 == 'lflags'
tcsetattr_flags = termios.TCSAFLUSH
+ do_close = False
if hasattr(termios, 'TCSASOFT'):
tcsetattr_flags |= termios.TCSASOFT
try:
termios.tcsetattr(fd, tcsetattr_flags, new)
passwd = _raw_input(prompt, stream, input=input)
+ except (EOFError, KeyboardInterrupt):
+ do_close = True
+ raise
finally:
termios.tcsetattr(fd, tcsetattr_flags, old)
- stream.flush() # issue7208
+ if do_close:
+ stream.write('\n')
+ stream.close()
+ else:
+ stream.flush() # issue7208
except termios.error as e:
if passwd is not None:
# _raw_input succeeded. The final tcsetattr failed. Reraise
# instead of leaving the terminal in an unknown state.
+ stream.write('\n')
+ stream.close()
raise
# We can't control the tty or stdin. Give up and use normal IO.
# fallback_getpass() raises an appropriate warning.
@@ -83,6 +93,8 @@
passwd = fallback_getpass(prompt, stream)
stream.write('\n')
+ if tty is not None:
+ stream.close()
return passwd
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com