DebugClients/Python3/getpass.py

changeset 5241
883e7084818d
parent 5238
682d0f6a6074
parent 5240
71c51aae2f4e
child 5243
f6346f4b46c2
equal deleted inserted replaced
5238:682d0f6a6074 5241:883e7084818d
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2016 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 (string)
27 """
28 # this is copied from the oroginal getpass.py
29
30 import os
31
32 for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
33 user = os.environ.get(name)
34 if user:
35 return user
36
37 # If this fails, the exception will "explain" why
38 import pwd
39 return pwd.getpwuid(os.getuid())[0]
40
41
42 def getpass(prompt='Password: '):
43 """
44 Function to prompt for a password, with echo turned off.
45
46 @param prompt Prompt to be shown to the user (string)
47 @return Password entered by the user (string)
48 """
49 return input(prompt, False)
50
51 unix_getpass = getpass
52 win_getpass = getpass
53 default_getpass = getpass
54
55 #
56 # eflag: noqa = M702

eric ide

mercurial