Package wtf :: Module config :: Class Parser
[hide private]
[frames] | no frames]

Class Parser

source code

object --+
         |
        Parser

Simplified config file parser

The ConfigParser module does too much magic (partially not even documented). Further we don't need all the set and save stuff here, so we write our own - clean - variant. This variant just reads the stuff and does not apply any typing or transformation. It also uses a better design...

Instance Methods [hide private]
 
__init__(self, config, charset='latin-1')
Initialization
source code
 
parse(self, fp, filename, _included=None)
Reads from fp until EOF and parses line by line
source code
 
_cast(self, section)
Cast the options of a section to python types
source code
bool
_is_comment(self, line)
Decide if line is comment
source code
str
_try_section(self, line)
Try to extract a section header from line
source code
tuple
_parse_option(self, line)
Parse line as option (name [:=] value)
source code
Section
_make_section(self)
Make a new Section instance
source code
any
_make_option(self, valuelist)
Make a new option value
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
str _charset
Default config charset
Config _config
Config instance to feed
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, config, charset='latin-1')
(Constructor)

source code 
Initialization
Parameters:
  • config (Config) - Config instance
  • charset (str) - Default config charset
Overrides: object.__init__

parse(self, fp, filename, _included=None)

source code 
Reads from fp until EOF and parses line by line
Parameters:
  • fp (file) - The stream to read from
  • filename (basestring) - The filename used for relative includes and error messages
  • _included (set) - Set of already included filenames for recursion check
Raises:

_cast(self, section)

source code 
Cast the options of a section to python types
Parameters:
  • section (Section) - The section to process

_is_comment(self, line)

source code 
Decide if line is comment
Parameters:
  • line (str) - The line to inspect
Returns: bool
Is line is comment line?

_try_section(self, line)

source code 
Try to extract a section header from line
Parameters:
  • line (str) - The line to process
Returns: str
The section header name or None

_parse_option(self, line)

source code 
Parse line as option (name [:=] value)
Parameters:
  • line (str) - The line to process
Returns: tuple
The name and the value (both None if an error occured)

_make_section(self)

source code 
Make a new Section instance
Returns: Section
The new Section instance

_make_option(self, valuelist)

source code 

Make a new option value

The function will do the right thing[tm] in order to determine the correct option type based on valuelist.

Parameters:
  • valuelist (list) - List of values of that option
Returns: any
Option type appropriate for the valuelist