src/eric7/DebugClients/Python/getpass.py

branch
eric7-maintenance
changeset 9264
18a7312cfdb3
parent 9221
bf71ee032bb4
child 9482
a2bc06a54d9d
equal deleted inserted replaced
9241:d23e9854aea4 9264:18a7312cfdb3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2004 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing utilities to get a password and/or the current user name.
8
9 getpass(prompt) - prompt for a password, with echo turned off
10 getuser() - get the user name from the environment or password database
11
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.
14 """
15
16 __all__ = ["getpass", "getuser"]
17
18
19 def getuser():
20 """
21 Function to get the username from the environment or password database.
22
23 First try various environment variables, then the password
24 database. This works on Windows as long as USERNAME is set.
25
26 @return username
27 @rtype str
28 """
29 # this is copied from the original getpass.py
30
31 import os
32
33 for name in ("LOGNAME", "USER", "LNAME", "USERNAME"):
34 user = os.environ.get(name)
35 if user:
36 return user
37
38 # If this fails, the exception will "explain" why
39 import pwd
40
41 return pwd.getpwuid(os.getuid())[0]
42
43
44 def getpass(prompt="Password: ", stream=None):
45 """
46 Function to prompt for a password, with echo turned off.
47
48 @param prompt Prompt to be shown to the user
49 @type str
50 @param stream input stream to read from (ignored)
51 @type file
52 @return Password entered by the user
53 @rtype str
54 """
55 return input(prompt, False) # secok
56
57
58 unix_getpass = getpass
59 win_getpass = getpass
60 default_getpass = getpass
61 fallback_getpass = getpass

eric ide

mercurial