Skip to content

Commit c608b7a

Browse files
committed
Update
1 parent ba236ee commit c608b7a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

Lib/getpass.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ def unix_getpass(prompt='Password: ', stream=None, *, echochar=None):
8080
tcsetattr_flags |= termios.TCSASOFT
8181
try:
8282
termios.tcsetattr(fd, tcsetattr_flags, new)
83-
if echochar:
84-
passwd = _input_with_echochar(prompt, stream, input,
85-
echochar)
86-
else:
87-
passwd = _raw_input(prompt, stream, input=input)
83+
passwd = _raw_input(prompt, stream, input=input,
84+
echochar=echochar)
85+
8886
finally:
8987
termios.tcsetattr(fd, tcsetattr_flags, old)
9088
stream.flush() # issue7208
@@ -151,7 +149,7 @@ def _check_echochar(echochar):
151149
f"got: {echochar!r}")
152150

153151

154-
def _raw_input(prompt="", stream=None, input=None):
152+
def _raw_input(prompt="", stream=None, input=None, echochar=None):
155153
# This doesn't save the string in the GNU readline history.
156154
if not stream:
157155
stream = sys.stderr
@@ -168,6 +166,8 @@ def _raw_input(prompt="", stream=None, input=None):
168166
stream.write(prompt)
169167
stream.flush()
170168
# NOTE: The Python C API calls flockfile() (and unlock) during readline.
169+
if echochar:
170+
return _readline_with_echochar(stream, input, echochar)
171171
line = input.readline()
172172
if not line:
173173
raise EOFError
@@ -176,14 +176,7 @@ def _raw_input(prompt="", stream=None, input=None):
176176
return line
177177

178178

179-
def _input_with_echochar(prompt, stream, input, echochar):
180-
if not stream:
181-
stream = sys.stderr
182-
if not input:
183-
input = sys.stdin
184-
prompt = str(prompt)
185-
stream.write(prompt)
186-
stream.flush()
179+
def _readline_with_echochar(stream, input, echochar):
187180
passwd = ""
188181
eof_pressed = False
189182
while True:

0 commit comments

Comments
 (0)