From 41e30183367e52450fdf7316cf32bfa4e9a78afc Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 21 Apr 2008 21:31:08 +0000 Subject: [PATCH] If sys.stdin is not a tty, fall back to default_getpass after printing a warning instead of failing with a termios.error. --- Lib/getpass.py | 4 ++++ Misc/NEWS | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Lib/getpass.py b/Lib/getpass.py index 6b786122ecb..07c89ff0b97 100644 --- a/Lib/getpass.py +++ b/Lib/getpass.py @@ -24,6 +24,10 @@ def unix_getpass(prompt='Password: ', stream=None): if stream is None: stream = sys.stdout + if not sys.stdin.isatty(): + print >>sys.stderr, "Warning: sys.stdin is not a tty." + return default_getpass(prompt) + try: fd = sys.stdin.fileno() except: diff --git a/Misc/NEWS b/Misc/NEWS index 660651a86b5..51f6ce14c8f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -37,6 +37,9 @@ Extensions Modules Library ------- +- getpass.getpass() now works when sys.stdin is not a tty by printing a warning + and falling back to sys.stdin.readline instead of raising termios.error. + - Issue #2014: Allow XML-RPC datetime objects to have dates before 1900-01-01.