Message399004
The `sys.stdin is not sys.__stdin__` check is not relevant information. We need to know whether msvcrt.getwch() works and that the user should be able to type the password in the console window. sys.__stdin__ could be a file object for the NUL device, a pipe, or a file.
Also, this check has never been implemented in POSIX. If I run `python -m idlelib` in Linux, getpass() still reads the password from the terminal instead of sys.stdin.
> IDLE's stdio connected to Shell passes isatty
IOBase.isatty() is more abstract than I expected, since it can be true for any stream that's "interactive". While FileIO.isatty() and os.isatty() are definitely wrong in Windows (i.e. they should not be true for NUL or a serial/parallel port), I see now that fixing isatty() doesn't solve the problem.
We need to directly check whether sys.stdin is a console. If so, we can reasonably assume that there's a visible, accessible console window. The check would be something like:
try:
_winapi.GetConsoleMode(msvcrt.get_osfhandle(sys.stdin.fileno()))
except (AttributeError, OSError):
return fallback_getpass(prompt, stream)
_winapi.GetConsoleMode() would need to be implemented.
This is inconsistent with Unix since it's not trying to open "CONIN$". But relying on the latter is problematic in Windows since it succeeds in any process that's attached to a console session, even if the console window is hidden or never created (i.e. CREATE_NO_WINDOW). |
|
Date |
User |
Action |
Args |
2021-08-05 13:22:41 | eryksun | set | recipients:
+ eryksun, terry.reedy, paul.moore, tim.golden, matejcik, zach.ware, steve.dower |
2021-08-05 13:22:40 | eryksun | set | messageid: <1628169760.98.0.404138205954.issue44762@roundup.psfhosted.org> |
2021-08-05 13:22:40 | eryksun | link | issue44762 messages |
2021-08-05 13:22:40 | eryksun | create | |
|