Prompt for password with echo off, using Windows getwch().
(prompt='Password: ', stream=None)
| 95 | |
| 96 | |
| 97 | def win_getpass(prompt='Password: ', stream=None): |
| 98 | """Prompt for password with echo off, using Windows getwch().""" |
| 99 | if sys.stdin is not sys.__stdin__: |
| 100 | return fallback_getpass(prompt, stream) |
| 101 | |
| 102 | for c in prompt: |
| 103 | msvcrt.putwch(c) |
| 104 | pw = "" |
| 105 | while 1: |
| 106 | c = msvcrt.getwch() |
| 107 | if c == '\r' or c == '\n': |
| 108 | break |
| 109 | if c == '\003': |
| 110 | raise KeyboardInterrupt |
| 111 | if c == '\b': |
| 112 | pw = pw[:-1] |
| 113 | else: |
| 114 | pw = pw + c |
| 115 | msvcrt.putwch('\r') |
| 116 | msvcrt.putwch('\n') |
| 117 | return pw |
| 118 | |
| 119 | |
| 120 | def fallback_getpass(prompt='Password: ', stream=None): |
nothing calls this directly
no test coverage detected