summaryrefslogtreecommitdiffstats
path: root/Lib/getpass.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>1999-10-18 22:25:22 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>1999-10-18 22:25:22 (GMT)
commit88d23309e937df1cf99e9a649a7b2684fc1159c5 (patch)
treeaf6dc3c9aed0354bc4f8dc1bae31372abac0fb34 /Lib/getpass.py
parentf8d8e07601d06e709000429f3b504a0e5a0963bf (diff)
downloadcpython-88d23309e937df1cf99e9a649a7b2684fc1159c5.zip
cpython-88d23309e937df1cf99e9a649a7b2684fc1159c5.tar.gz
cpython-88d23309e937df1cf99e9a649a7b2684fc1159c5.tar.bz2
print a warning if the password will be echoed.
At import time, getpass will be bound to the appropriate platform-specific function. If the platform's echo-disabler is not available, default_getpass, which prints the warning, will be used
Diffstat (limited to 'Lib/getpass.py')
-rw-r--r--Lib/getpass.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/Lib/getpass.py b/Lib/getpass.py
index 952e023..19843d7 100644
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -3,43 +3,27 @@
getpass(prompt) - prompt for a password, with echo turned off
getuser() - get the user name from the environment or password database
+On Windows, the msvcrt module will be used.
+On the Mac EasyDialogs.AskPassword is used, if available.
+
Authors: Piers Lauder (original)
Guido van Rossum (Windows support and cleanup)
"""
+import sys
-def getpass(prompt='Password: '):
+def unix_getpass(prompt='Password: '):
"""Prompt for a password, with echo turned off.
Restore terminal settings at end.
-
- On Windows, this calls win_getpass(prompt) which uses the
- msvcrt module to get the same effect.
-
- On the Mac EasyDialogs.AskPassword is used, if available.
-
"""
- import sys
try:
fd = sys.stdin.fileno()
except:
return default_getpass(prompt)
- try:
- import termios, TERMIOS
- except ImportError:
- try:
- import msvcrt
- except ImportError:
- try:
- from EasyDialogs import AskPassword
- except ImportError:
- return default_getpass(prompt)
- else:
- return AskPassword(prompt)
- else:
- return win_getpass(prompt)
+ getpass = default_getpass
old = termios.tcgetattr(fd) # a copy to save
new = old[:]
@@ -76,6 +60,7 @@ def win_getpass(prompt='Password: '):
def default_getpass(prompt='Password: '):
+ print "Warning: Problem with getpass. Passwords may be echoed."
return _raw_input(prompt)
@@ -112,3 +97,22 @@ def getuser():
# If this fails, the exception will "explain" why
import pwd
return pwd.getpwuid(os.getuid())[0]
+
+# Bind the name getpass to the appropriate function
+try:
+ import termios, TERMIOS
+except ImportError:
+ try:
+ import msvcrt
+ except ImportError:
+ try:
+ from EasyDialogs import AskPassword
+ except ImportError:
+ getpass = default_getpass
+ else:
+ getpass = AskPassword
+ else:
+ getpass = win_getpass
+else:
+ getpass = unix_getpass
+