Back to index

python3.2  3.2.2
Classes | Functions | Variables
pwd Namespace Reference

Classes

class  Passwd

Functions

def __nullpathconv
def __unixpathconv
def __get_field_sep
def __read_passwd_file
def getpwuid
def getpwnam
def getpwall

Variables

list __passwd_path = []
 passwd_file = None
tuple __f = open(__i, 'r')
dictionary __field_sep = {':': __unixpathconv}

Function Documentation

def pwd.__get_field_sep (   record) [private]

Definition at line 106 of file pwd.py.

00106 
00107 def __get_field_sep(record):
00108     fs = None
00109     for c in __field_sep.keys():
00110         # there should be 6 delimiter characters (for 7 fields)
00111         if record.count(c) == 6:
00112             fs = c
00113             break
00114     if fs:
00115         return fs
00116     else:
00117         raise KeyError('>> passwd database fields not delimited <<')
00118 
00119 # class to match the new record field name accessors.
00120 # the resulting object is intended to behave like a read-only tuple,
# with each member also accessible by a field name.

Here is the caller graph for this function:

def pwd.__nullpathconv (   path) [private]

Definition at line 82 of file pwd.py.

00082 
00083 def __nullpathconv(path):
00084     return path.replace(os.altsep, os.sep)

def pwd.__read_passwd_file ( ) [private]

Definition at line 159 of file pwd.py.

00159 
00160 def __read_passwd_file():
00161     if passwd_file:
00162         passwd = open(passwd_file, 'r')
00163     else:
00164         raise KeyError('>> no password database <<')
00165     uidx = {}
00166     namx = {}
00167     sep = None
00168     while True:
00169         entry = passwd.readline().strip()
00170         if len(entry) > 6:
00171             if sep is None:
00172                 sep = __get_field_sep(entry)
00173             fields = entry.split(sep)
00174             for i in (2, 3):
00175                 fields[i] = int(fields[i])
00176             for i in (5, 6):
00177                 fields[i] = __field_sep[sep](fields[i])
00178             record = Passwd(*fields)
00179             if fields[2] not in uidx:
00180                 uidx[fields[2]] = record
00181             if fields[0] not in namx:
00182                 namx[fields[0]] = record
00183         elif len(entry) > 0:
00184             pass                         # skip empty or malformed records
00185         else:
00186             break
00187     passwd.close()
00188     if len(uidx) == 0:
00189         raise KeyError
00190     return (uidx, namx)
00191 
# return the passwd database entry by UID

Here is the call graph for this function:

Here is the caller graph for this function:

def pwd.__unixpathconv (   path) [private]

Definition at line 85 of file pwd.py.

00085 
00086 def __unixpathconv(path):
00087     # two known drive letter variations: "x;" and "$x"
00088     if path[0] == '$':
00089         conv = path[1] + ':' + path[2:]
00090     elif path[1] == ';':
00091         conv = path[0] + ':' + path[2:]
00092     else:
00093         conv = path
00094     return conv.replace(os.altsep, os.sep)
00095 
00096 # decide what field separator we can try to use - Unix standard, with
00097 # the platform's path separator as an option.  No special field conversion
00098 # handler is required when using the platform's path separator as field
00099 # separator, but are required for the home directory and shell fields when
# using the standard Unix (":") field separator.
def pwd.getpwall ( )

Definition at line 202 of file pwd.py.

00202 
00203 def getpwall():
00204     u, n = __read_passwd_file()
00205     return n.values()
00206 
# test harness

Here is the call graph for this function:

Here is the caller graph for this function:

def pwd.getpwnam (   name)

Definition at line 197 of file pwd.py.

00197 
00198 def getpwnam(name):
00199     u, n = __read_passwd_file()
00200     return n[name]
00201 
# return all the passwd database entries

Here is the call graph for this function:

Here is the caller graph for this function:

def pwd.getpwuid (   uid)

Definition at line 192 of file pwd.py.

00192 
00193 def getpwuid(uid):
00194     u, n = __read_passwd_file()
00195     return u[uid]
00196 
# return the passwd database entry by passwd name

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tuple pwd.__f = open(__i, 'r')

Definition at line 74 of file pwd.py.

Definition at line 100 of file pwd.py.

list pwd.__passwd_path = []

Definition at line 63 of file pwd.py.

Definition at line 71 of file pwd.py.