cpython: 100f632d4306 (original) (raw)

Mercurial > cpython

changeset 88206:100f632d4306 3.3

#18116: backport fix to 3.3 since real-world failure mode demonstrated. In issue 20074 it was pointed out that getpass would fail with a traceback if stdin was, for example /dev/null, which is a non-unlikely scenario. Also backported the tests from issue 17484 as modified by issue 18116. (What I really did was copy getpass.py and test_getpass.py from their state on tip as of 17bd04fbf3d3). [#18116]

R David Murray rdmurray@bitdance.com
date Fri, 27 Dec 2013 11:24:32 -0500
parents 7615c009e925
children 29a5a5b39dd6 a00842b783cf
files Lib/getpass.py Lib/test/test_getpass.py Lib/test/test_sundry.py Misc/NEWS
diffstat 4 files changed, 213 insertions(+), 45 deletions(-)[+] [-] Lib/getpass.py 97 Lib/test/test_getpass.py 155 Lib/test/test_sundry.py 1 Misc/NEWS 5

line wrap: on

line diff

--- a/Lib/getpass.py +++ b/Lib/getpass.py @@ -15,7 +15,11 @@ On the Mac EasyDialogs.AskPassword is us

Guido van Rossum (Windows support and cleanup)

Gregory P. Smith (tty support & GetPassWarning)

-import os, sys, warnings +import contextlib +import io +import os +import sys +import warnings all = ["getpass","getuser","GetPassWarning"] @@ -38,52 +42,57 @@ def unix_getpass(prompt='Password: ', st Always restores terminal settings before returning. """

-

+

def win_getpass(prompt='Password: ', stream=None):

new file mode 100644 --- /dev/null +++ b/Lib/test/test_getpass.py @@ -0,0 +1,155 @@ +import getpass +import os +import unittest +from io import BytesIO, StringIO +from unittest import mock +from test import support + +try:

+except ImportError:

+try:

+except ImportError:

+ +@mock.patch('os.environ') +class GetpassGetuserTest(unittest.TestCase): +

+

+

+ + +class GetpassRawinputTest(unittest.TestCase): +

+

+

+

+

+ + +# Some of these tests are a bit white-box. The functional requirement is that +# the password input be taken directly from the tty, and that it not be echoed +# on the screen, unless we are falling back to stderr/stdin. + +# Some of these might run on platforms without termios, but play it safe. +@unittest.skipUnless(termios, 'tests require system with termios') +class UnixGetpassTest(unittest.TestCase): +

+

+

+

+

+ + +if name == "main":

--- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -41,7 +41,6 @@ class TestUntestedModules(unittest.TestC import encodings import formatter

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,11 @@ Core and Builtins Library ------- +- Issue #18116: getpass was always getting an error when testing /dev/tty,