diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-06-14 00:00:37 +0000 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-06-14 00:00:37 +0000 |
commit | a73a964e51247ed169d322c725a3a18859f109a3 (patch) | |
tree | 3f752d117274d444bda44e85609aeac1acf313f3 /sys/lib/python/getpass.py | |
parent | e64efe273fcb921a61bf27d33b230c4e64fcd425 (diff) |
python, hg: tow outside the environment.
they've served us well, and can ride off into the sunset.
Diffstat (limited to 'sys/lib/python/getpass.py')
-rw-r--r-- | sys/lib/python/getpass.py | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/sys/lib/python/getpass.py b/sys/lib/python/getpass.py deleted file mode 100644 index 7cc0560c7..000000000 --- a/sys/lib/python/getpass.py +++ /dev/null @@ -1,127 +0,0 @@ -"""Utilities to get a password and/or the current user name. - -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 - -__all__ = ["getpass","getuser"] - -def unix_getpass(prompt='Password: ', stream=None): - """Prompt for a password, with echo turned off. - The prompt is written on stream, by default stdout. - - Restore terminal settings at end. - """ - if stream is None: - stream = sys.stdout - - try: - fd = sys.stdin.fileno() - except: - return default_getpass(prompt) - - 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, stream) - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old) - - stream.write('\n') - return passwd - - -def win_getpass(prompt='Password: ', stream=None): - """Prompt for password with echo off, using Windows getch().""" - if sys.stdin is not sys.__stdin__: - return default_getpass(prompt, stream) - 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: ', stream=None): - try: - ctl = open("/dev/consctl", "w") - ctl.write("rawon") - ctl.flush() - buf = _raw_input(prompt, stream) - ctl.write("rawoff") - ctl.flush() - ctl.close() - return buf; - except: - buf = _raw_input(prompt, stream) - return buf - -def _raw_input(prompt="", stream=None): - # A raw_input() replacement that doesn't save the string in the - # GNU readline history. - if stream is None: - stream = sys.stdout - prompt = str(prompt) - if prompt: - stream.write(prompt) - stream.flush() - 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. - - First try various environment variables, then the password - database. This works on Windows as long as USERNAME is set. - - """ - - import os - - 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] - -# Bind the name getpass to the appropriate function -try: - import termios - # it's possible there is an incompatible termios from the - # McMillan Installer, make sure we have a UNIX-compatible termios - termios.tcgetattr, termios.tcsetattr -except (ImportError, AttributeError): - getpass = default_getpass -else: - getpass = unix_getpass |