2 This module provides utlilities related to creating, reading, writing and parsing of linux-style passwd/shadow file.
8 This exception is raised when more than exactly one instance of a given field is contained within field list.
16 This exception is raised when an empty field name is encountered.
24 This exception is raised when an empty separator string is encountered.
32 This exception is raised when an empty line separator string is encountered.
40 This exception is raised when encountering invalid or non-uniform line.
48 This class provides methods to read and write to linux-style passwd/shadow files, ability to parse shadow-style lines into dicts and identifying password hashing algorithms used in linux-style hash format.
56 def __init__(self, line_format, separator=":
", newline="\n
"):
60 @param line_format List of field names, field names have to be unique and cannot be empty. Not all fields have to be in format list if dumping text.
61 @param separator String to use to separate fields in line
62 @param newline String to use as line separator
71 if x ==
"" or x
is None:
74 if separator
is None or separator ==
"":
77 if newline
is None or newline ==
"":
87 Parses line according to line_format.
89 @param line The line to be parsed
91 @returns The dict representation of given line
103 linedict.update({fname: fvalue})
110 Creates string line from fieldset and line_format
112 @param fields Dict of field values to fill line with
114 @returns String representation of give line data
121 line += str(linedata)
131 Prepares and adds new line to internal buffer.
133 @param fields Dict of field values to add to internal buffer as a line
139 Parsed line and adds appropriate dict to internal buffer.
141 @param line String representation of a given line
147 Prepares and returns text block representing all lines in internal buffer.
149 @returns String block representing internal buffer. Empty string when no lines in buffer.
159 Parses text block and adds its lines to internal buffer.
161 @param textblock String to load into internal buffer
167 if line
is not None and line !=
"":
This exception is raised when more than exactly one instance of a given field is contained within fie...
This exception is raised when an empty field name is encountered.
This exception is raised when an empty line separator string is encountered.
This exception is raised when an empty separator string is encountered.
This class provides methods to read and write to linux-style passwd/shadow files, ability to parse sh...
def dump_text(self)
Prepares and returns text block representing all lines in internal buffer.
def add_new_line(self, fields)
Prepares and adds new line to internal buffer.
def parse_line(self, line)
Parses line according to line_format.
def create_line(self, fields)
Creates string line from fieldset and line_format.
def add_line_from_text(self, line)
Parsed line and adds appropriate dict to internal buffer.
def __init__(self, line_format, separator=":", newline="\n")
Initialize parser.
def load_text(self, textblock)
Parses text block and adds its lines to internal buffer.