DebugClients/Python/getpass.py

changeset 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2004 - 2009 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 import sys
17
18 __all__ = ["getpass","getuser"]
19
20 def getuser():
21 """
22 Function to get the username from the environment or password database.
23
24 First try various environment variables, then the password
25 database. This works on Windows as long as USERNAME is set.
26
27 @return username (string)
28 """
29 # this is copied from the oroginal 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 return pwd.getpwuid(os.getuid())[0]
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 raw_input(prompt, 0)
50
51 unix_getpass = getpass
52 win_getpass = getpass
53 default_getpass = getpass

eric ide

mercurial