classification
Title: getpass broken in Py3k: must flush()
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, pjenvey
Priority: normal Keywords:

Created on 2007-12-28 00:14 by pjenvey, last changed 2008-01-01 16:31 by gvanrossum. This issue is now closed.

Files
File name Uploaded Description Edit
getpass_flush-r59601.diff pjenvey, 2007-12-28 00:14
Messages (2)
msg59011 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2007-12-28 00:14
getpass (in particular _raw_input, used by unix_getpass and 
default_getpass) prints out a password prompt to a stream (by default 
stdout) but doesn't flush that stream. It assumes calling 
sys.stdin.readline() to read the password causes stdout to be flushed 
(probably a libc file buffering behavior)

This is a problem in Py3k where file buffering is done by Python; 
getpass needs to manually flush the stream it prints the prompt to. 
Otherwise the prompt isn't printed until after the password is entered 
e.g.:

Python 3.0a2 (py3k:59601, Dec 27 2007, 14:28:14) 
[GCC 4.1.3 20071209 (prerelease) (Debian 4.1.2-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass
>>> getpass.getpass()

<no prompt is printed, i type 'foo\n', and only afterwards is the prompt 
printed>

Password: 
'foo'
>>>

Windows doesn't use _raw_input so it wouldn't see this issue.

Attached is a patch to flush the stream. There's no getpass tests so I 
didn't get around to creating one for this issue. Ideally we'd test 
getpass via spawning a python subprocess and ensuring its I/O looked 
correct.

This was noticed on Jython as its file object is now based off Py3k's
msg59071 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-01 16:31
Committed revision 59646.
History
Date User Action Args
2008-01-01 16:31:54gvanrossumsetstatus: open -> closed
type: behavior
resolution: accepted
messages: + msg59071
nosy: + gvanrossum
2007-12-28 00:14:34pjenveycreate