mirror of
https://github.com/python/cpython.git
synced 2025-08-07 02:18:59 +00:00
Use the getpass module instead of having platform-specific echo on/off
code here.
This commit is contained in:
parent
c8f859a487
commit
ae9ee7329d
1 changed files with 5 additions and 18 deletions
|
@ -476,30 +476,17 @@ class FancyURLopener(URLopener):
|
||||||
|
|
||||||
def prompt_user_passwd(self, host, realm):
|
def prompt_user_passwd(self, host, realm):
|
||||||
# Override this in a GUI environment!
|
# Override this in a GUI environment!
|
||||||
|
import getpass
|
||||||
try:
|
try:
|
||||||
user = raw_input("Enter username for %s at %s: " %
|
user = raw_input("Enter username for %s at %s: " %
|
||||||
(realm, host))
|
(realm, host))
|
||||||
self.echo_off()
|
passwd = getpass.getpass(
|
||||||
try:
|
|
||||||
passwd = raw_input(
|
|
||||||
"Enter password for %s in %s at %s: " %
|
"Enter password for %s in %s at %s: " %
|
||||||
(user, realm, host))
|
(user, realm, host))
|
||||||
finally:
|
|
||||||
self.echo_on()
|
|
||||||
return user, passwd
|
return user, passwd
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return None, None
|
|
||||||
|
|
||||||
def echo_off(self):
|
|
||||||
# XXX Is this sufficient???
|
|
||||||
if hasattr(os, "system"):
|
|
||||||
os.system("stty -echo")
|
|
||||||
|
|
||||||
def echo_on(self):
|
|
||||||
# XXX Is this sufficient???
|
|
||||||
if hasattr(os, "system"):
|
|
||||||
print
|
print
|
||||||
os.system("stty echo")
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
# Utility functions
|
# Utility functions
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue