]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Don't catch interrupts in getpass() -- the finally clause will reset
authorGuido van Rossum <guido@python.org>
Fri, 12 Jun 1998 14:28:38 +0000 (14:28 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 12 Jun 1998 14:28:38 +0000 (14:28 +0000)
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).

Lib/getpass.py

index 8bd75233f139f4de1db0c4d9d2fb2ccaab5b3d63..d67240eaf8aaecd19359383a2b5cb36b5a551912 100644 (file)
@@ -36,8 +36,7 @@ def getpass(prompt='Password: '):
        new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags'
        try:
                termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
-               try: passwd = raw_input(prompt)
-               except KeyboardInterrupt: passwd = None
+               passwd = raw_input(prompt)
        finally:
                termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
 
@@ -55,6 +54,8 @@ def win_getpass(prompt='Password: '):
                c = msvcrt.getch()
                if c == '\r' or c == '\n':
                        break
+               if c == '\003':
+                       raise KeyboardInterrupt
                if c == '\b':
                        pw = pw[:-1]
                else: