Commit c3da02e9 authored by Guido van Rossum's avatar Guido van Rossum

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).
parent e7c41937
...@@ -36,8 +36,7 @@ def getpass(prompt='Password: '): ...@@ -36,8 +36,7 @@ def getpass(prompt='Password: '):
new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags' new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags'
try: try:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new) termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
try: passwd = raw_input(prompt) passwd = raw_input(prompt)
except KeyboardInterrupt: passwd = None
finally: finally:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old) termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
...@@ -55,6 +54,8 @@ def win_getpass(prompt='Password: '): ...@@ -55,6 +54,8 @@ def win_getpass(prompt='Password: '):
c = msvcrt.getch() c = msvcrt.getch()
if c == '\r' or c == '\n': if c == '\r' or c == '\n':
break break
if c == '\003':
raise KeyboardInterrupt
if c == '\b': if c == '\b':
pw = pw[:-1] pw = pw[:-1]
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment