Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae9ee73

Browse files
committed
Use the getpass module instead of having platform-specific echo on/off
code here.
1 parent c8f859a commit ae9ee73

1 file changed

Lines changed: 5 additions & 18 deletions

File tree

Lib/urllib.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,30 +476,17 @@ def get_user_passwd(self, host, realm, clear_cache = 0):
476476

477477
def prompt_user_passwd(self, host, realm):
478478
# Override this in a GUI environment!
479+
import getpass
479480
try:
480481
user = raw_input("Enter username for %s at %s: " %
481482
(realm, host))
482-
self.echo_off()
483-
try:
484-
passwd = raw_input(
485-
"Enter password for %s in %s at %s: " %
486-
(user, realm, host))
487-
finally:
488-
self.echo_on()
483+
passwd = getpass.getpass(
484+
"Enter password for %s in %s at %s: " %
485+
(user, realm, host))
489486
return user, passwd
490487
except KeyboardInterrupt:
491-
return None, None
492-
493-
def echo_off(self):
494-
# XXX Is this sufficient???
495-
if hasattr(os, "system"):
496-
os.system("stty -echo")
497-
498-
def echo_on(self):
499-
# XXX Is this sufficient???
500-
if hasattr(os, "system"):
501488
print
502-
os.system("stty echo")
489+
return None, None
503490

504491

505492
# Utility functions

0 commit comments

Comments
 (0)