diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-01-14 23:47:14 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-01-14 23:47:14 (GMT) |
commit | 07e99cb77406e1bc84606f49b743e41b0de8a6d5 (patch) | |
tree | b922cda3a970bffa797269fd550f8d8b032afe5b /Lib/getpass.py | |
parent | 88869f9787cd4ceb2298e4b13980beb057687824 (diff) | |
download | cpython-07e99cb77406e1bc84606f49b743e41b0de8a6d5.zip cpython-07e99cb77406e1bc84606f49b743e41b0de8a6d5.tar.gz cpython-07e99cb77406e1bc84606f49b743e41b0de8a6d5.tar.bz2 |
Whitespace normalization.
Diffstat (limited to 'Lib/getpass.py')
-rw-r--r-- | Lib/getpass.py | 151 |
1 files changed, 75 insertions, 76 deletions
diff --git a/Lib/getpass.py b/Lib/getpass.py index b81026f..918f2ed 100644 --- a/Lib/getpass.py +++ b/Lib/getpass.py @@ -14,106 +14,105 @@ On the Mac EasyDialogs.AskPassword is used, if available. import sys def unix_getpass(prompt='Password: '): - """Prompt for a password, with echo turned off. + """Prompt for a password, with echo turned off. - Restore terminal settings at end. - """ + Restore terminal settings at end. + """ - try: - fd = sys.stdin.fileno() - except: - return default_getpass(prompt) + try: + fd = sys.stdin.fileno() + except: + return default_getpass(prompt) - getpass = default_getpass - old = termios.tcgetattr(fd) # a copy to save - new = old[:] + getpass = default_getpass + old = termios.tcgetattr(fd) # a copy to save + new = old[:] - new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags' - try: - termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new) - passwd = _raw_input(prompt) - finally: - termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old) + new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags' + try: + termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new) + passwd = _raw_input(prompt) + finally: + termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old) - sys.stdout.write('\n') - return passwd + sys.stdout.write('\n') + return passwd def win_getpass(prompt='Password: '): - """Prompt for password with echo off, using Windows getch().""" - import msvcrt - for c in prompt: - msvcrt.putch(c) - pw = "" - while 1: - c = msvcrt.getch() - if c == '\r' or c == '\n': - break - if c == '\003': - raise KeyboardInterrupt - if c == '\b': - pw = pw[:-1] - else: - pw = pw + c - msvcrt.putch('\r') - msvcrt.putch('\n') - return pw + """Prompt for password with echo off, using Windows getch().""" + import msvcrt + for c in prompt: + msvcrt.putch(c) + pw = "" + while 1: + c = msvcrt.getch() + if c == '\r' or c == '\n': + break + if c == '\003': + raise KeyboardInterrupt + if c == '\b': + pw = pw[:-1] + else: + pw = pw + c + msvcrt.putch('\r') + msvcrt.putch('\n') + return pw def default_getpass(prompt='Password: '): - print "Warning: Problem with getpass. Passwords may be echoed." - return _raw_input(prompt) + print "Warning: Problem with getpass. Passwords may be echoed." + return _raw_input(prompt) def _raw_input(prompt=""): - # A raw_input() replacement that doesn't save the string in the - # GNU readline history. - import sys - prompt = str(prompt) - if prompt: - sys.stdout.write(prompt) - line = sys.stdin.readline() - if not line: - raise EOFError - if line[-1] == '\n': - line = line[:-1] - return line + # A raw_input() replacement that doesn't save the string in the + # GNU readline history. + import sys + prompt = str(prompt) + if prompt: + sys.stdout.write(prompt) + line = sys.stdin.readline() + if not line: + raise EOFError + if line[-1] == '\n': + line = line[:-1] + return line def getuser(): - """Get the username from the environment or password database. + """Get the username from the environment or password database. - First try various environment variables, then the password - database. This works on Windows as long as USERNAME is set. + First try various environment variables, then the password + database. This works on Windows as long as USERNAME is set. - """ + """ - import os + import os - for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'): - user = os.environ.get(name) - if user: - return user + for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'): + user = os.environ.get(name) + if user: + return user - # If this fails, the exception will "explain" why - import pwd - return pwd.getpwuid(os.getuid())[0] + # 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 + 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 + 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 - + getpass = unix_getpass |