src/eric7/DebugClients/Python/getpass.py

branch
eric7
changeset 9482
a2bc06a54d9d
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
equal deleted inserted replaced
9481:0b936ff1bbb9 9482:a2bc06a54d9d
10 getuser() - get the user name from the environment or password database 10 getuser() - get the user name from the environment or password database
11 11
12 This module is a replacement for the one found in the Python distribution. It 12 This module is a replacement for the one found in the Python distribution. It
13 is to provide a debugger compatible variant of the a.m. functions. 13 is to provide a debugger compatible variant of the a.m. functions.
14 """ 14 """
15
16 import os
17
18 try:
19 import pwd
20 except ImportError:
21 pwd = None
15 22
16 __all__ = ["getpass", "getuser"] 23 __all__ = ["getpass", "getuser"]
17 24
18 25
19 def getuser(): 26 def getuser():
26 @return username 33 @return username
27 @rtype str 34 @rtype str
28 """ 35 """
29 # this is copied from the original getpass.py 36 # this is copied from the original getpass.py
30 37
31 import os
32
33 for name in ("LOGNAME", "USER", "LNAME", "USERNAME"): 38 for name in ("LOGNAME", "USER", "LNAME", "USERNAME"):
34 user = os.environ.get(name) 39 user = os.environ.get(name)
35 if user: 40 if user:
36 return user 41 return user
37 42
38 # If this fails, the exception will "explain" why 43 # If this fails, the exception will "explain" why
39 import pwd 44 if pwd:
45 return pwd.getpwuid(os.getuid())[0]
40 46
41 return pwd.getpwuid(os.getuid())[0] 47 return "<unknown"
42 48
43 49
44 def getpass(prompt="Password: ", stream=None): 50 def getpass(prompt="Password: ", stream=None):
45 """ 51 """
46 Function to prompt for a password, with echo turned off. 52 Function to prompt for a password, with echo turned off.

eric ide

mercurial