Eryk Sun <eryk...@gmail.com> added the comment:

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).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44762>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to