]> granicus.if.org Git - python/commitdiff
If sys.stdin is not a tty, fall back to default_getpass after printing
authorGregory P. Smith <greg@mad-scientist.com>
Mon, 21 Apr 2008 21:31:08 +0000 (21:31 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Mon, 21 Apr 2008 21:31:08 +0000 (21:31 +0000)
a warning instead of failing with a termios.error.

Lib/getpass.py
Misc/NEWS

index 6b786122ecb71ce9146112eaaa52786fdcbf90f5..07c89ff0b978d3b44e3ff9c6316d29f1162b7354 100644 (file)
@@ -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:
index 660651a86b5e52658366ef28f03e9aed11eeefd8..51f6ce14c8f72e98fe165a0bc25581cb605a4e06 100644 (file)
--- 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.