Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
getpass Namespace Reference

Functions

def unix_getpass
 
def win_getpass
 
def default_getpass
 
def getuser
 

Variables

list __all__ = ["getpass","getuser"]
 
 getpass = default_getpass
 

Detailed Description

Utilities to get a password and/or the current user name.

getpass(prompt) - prompt for a password, with echo turned off
getuser() - get the user name from the environment or password database

On Windows, the msvcrt module will be used.
On the Mac EasyDialogs.AskPassword is used, if available.

Function Documentation

def getpass.default_getpass (   prompt = 'Password: ')

Definition at line 66 of file getpass.py.

References locale.str().

66 
67 def default_getpass(prompt='Password: '):
68  print "Warning: Problem with getpass. Passwords may be echoed."
69  return _raw_input(prompt)
70 
def getpass.getuser ( )
Get the username from the environment or password database.

First try various environment variables, then the password
database.  This works on Windows as long as USERNAME is set.

Definition at line 85 of file getpass.py.

85 
86 def getuser():
87  """Get the username from the environment or password database.
88 
89  First try various environment variables, then the password
90  database. This works on Windows as long as USERNAME is set.
91 
92  """
93 
94  import os
95 
96  for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
97  user = os.environ.get(name)
98  if user:
99  return user
100 
101  # If this fails, the exception will "explain" why
102  import pwd
103  return pwd.getpwuid(os.getuid())[0]
104 
105 # Bind the name getpass to the appropriate function
106 try:
import termios
def getpass.unix_getpass (   prompt = 'Password: ')
Prompt for a password, with echo turned off.

Restore terminal settings at end.

Definition at line 18 of file getpass.py.

References default_getpass().

18 
19 def unix_getpass(prompt='Password: '):
20  """Prompt for a password, with echo turned off.
21 
22  Restore terminal settings at end.
23  """
24 
25  try:
26  fd = sys.stdin.fileno()
27  except:
28  return default_getpass(prompt)
29 
30  old = termios.tcgetattr(fd) # a copy to save
31  new = old[:]
32 
33  new[3] = new[3] & ~termios.ECHO # 3 == 'lflags'
34  try:
35  termios.tcsetattr(fd, termios.TCSADRAIN, new)
36  passwd = _raw_input(prompt)
37  finally:
38  termios.tcsetattr(fd, termios.TCSADRAIN, old)
39 
40  sys.stdout.write('\n')
41  return passwd
42 
def getpass.win_getpass (   prompt = 'Password: ')
Prompt for password with echo off, using Windows getch().

Definition at line 43 of file getpass.py.

References default_getpass().

43 
44 def win_getpass(prompt='Password: '):
45  """Prompt for password with echo off, using Windows getch()."""
46  if sys.stdin is not sys.__stdin__:
47  return default_getpass(prompt)
48  import msvcrt
49  for c in prompt:
50  msvcrt.putch(c)
51  pw = ""
52  while 1:
53  c = msvcrt.getch()
54  if c == '\r' or c == '\n':
55  break
56  if c == '\003':
57  raise KeyboardInterrupt
58  if c == '\b':
59  pw = pw[:-1]
60  else:
61  pw = pw + c
62  msvcrt.putch('\r')
63  msvcrt.putch('\n')
64  return pw
65 

Variable Documentation

list __all__ = ["getpass","getuser"]

Definition at line 16 of file getpass.py.

getpass = default_getpass

Definition at line 114 of file getpass.py.