MCPcopy Index your code
hub / github.com/python/cpython / _get_terminal_ctrl_chars

Function _get_terminal_ctrl_chars

Lib/getpass.py:44–65  ·  view source on GitHub ↗

Extract control characters from terminal settings. Returns a dict mapping control char names to their str values. Falls back to POSIX defaults if termios is not available or if the control character is not supported by termios.

(fd)

Source from the content-addressed store, hash-verified

42
43
44def _get_terminal_ctrl_chars(fd):
45 """Extract control characters from terminal settings.
46
47 Returns a dict mapping control char names to their str values.
48
49 Falls back to POSIX defaults if termios is not available
50 or if the control character is not supported by termios.
51 """
52 ctrl = dict(_POSIX_CTRL_CHARS)
53 try:
54 old = termios.tcgetattr(fd)
55 cc = old[6] # Index 6 is the control characters array
56 except (termios.error, OSError):
57 return ctrl
58
59 # Use defaults for Backspace (BS) and Ctrl+A/E/K (SOH/ENQ/VT)
60 # as they are not in the termios control characters array.
61 for name in ('ERASE', 'KILL', 'WERASE', 'LNEXT', 'EOF', 'INTR'):
62 cap = getattr(termios, f'V{name}')
63 if cap < len(cc):
64 ctrl[name] = cc[cap].decode('latin-1')
65 return ctrl
66
67
68def unix_getpass(prompt='Password: ', stream=None, *, echo_char=None):

Callers 1

unix_getpassFunction · 0.85

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…