Skip to content

Commit c3da02e

Browse files
committed
Don't catch interrupts in getpass() -- the finally clause will reset
the tty and the caller can deal with the interrupt. In the windows version, recognize ^C and raise KeyboardInterrupt (not sure if this is needed, but can't hurt).
1 parent e7c4193 commit c3da02e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Lib/getpass.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def getpass(prompt='Password: '):
3636
new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags'
3737
try:
3838
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
39-
try: passwd = raw_input(prompt)
40-
except KeyboardInterrupt: passwd = None
39+
passwd = raw_input(prompt)
4140
finally:
4241
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
4342

@@ -55,6 +54,8 @@ def win_getpass(prompt='Password: '):
5554
c = msvcrt.getch()
5655
if c == '\r' or c == '\n':
5756
break
57+
if c == '\003':
58+
raise KeyboardInterrupt
5859
if c == '\b':
5960
pw = pw[:-1]
6061
else:

0 commit comments

Comments
 (0)