Prompt for password with echo off, using Windows getwch().
(prompt='Password: ', stream=None, *, echo_char=None)
| 154 | |
| 155 | |
| 156 | def win_getpass(prompt='Password: ', stream=None, *, echo_char=None): |
| 157 | """Prompt for password with echo off, using Windows getwch().""" |
| 158 | if sys.stdin is not sys.__stdin__: |
| 159 | return fallback_getpass(prompt, stream) |
| 160 | _check_echo_char(echo_char) |
| 161 | |
| 162 | for c in prompt: |
| 163 | msvcrt.putwch(c) |
| 164 | pw = "" |
| 165 | while 1: |
| 166 | c = msvcrt.getwch() |
| 167 | if c == '\r' or c == '\n': |
| 168 | break |
| 169 | if c == '\003': |
| 170 | raise KeyboardInterrupt |
| 171 | if c == '\b': |
| 172 | if echo_char and pw: |
| 173 | msvcrt.putwch('\b') |
| 174 | msvcrt.putwch(' ') |
| 175 | msvcrt.putwch('\b') |
| 176 | pw = pw[:-1] |
| 177 | else: |
| 178 | pw = pw + c |
| 179 | if echo_char: |
| 180 | msvcrt.putwch(echo_char) |
| 181 | msvcrt.putwch('\r') |
| 182 | msvcrt.putwch('\n') |
| 183 | return pw |
| 184 | |
| 185 | |
| 186 | def fallback_getpass(prompt='Password: ', stream=None, *, echo_char=None): |
nothing calls this directly
no test coverage detected
searching dependent graphs…