The old_config_parser module

An improved version of ConfigParser

Classes

ConfigParser

class src.tools.old_config_parser.ConfigParser(filename, optionDefaults, substitutionDefaults=None)

A wrapper class for a configuration file parser.

MyConfigParser wraps the ConfigParser.ConfigParser object to add some extra functionality, including getting lists of tuples and automatically writing to the configuration file when values are changed (or when the requested data is not present).

Parameters :

filename : str

The path to the configuration file.

optionDefaults : dict

A dictionary of default values for the configuration parameters. The keys should be tuples of the form (section name, option name).

substitutionDefaults : dict

A dictionary of values to be used in variable substitutions in the configuration file.

Methods

get(section, option)

Read a string value for a specified key in a specified section.

Parameters :

section : str

The section from which to read the value.

option : str

The key within section whose value should be read.

Returns :

str :

The value associated with the key option in section section.

getBoolean(section, option)

Read a boolean value for a specified key in a specified section.

If the specified key does not exist, it will be added (adding the section, also, if necessary).

Parameters :

section : str

The section from which to read the value.

option : str

The key within section whose value should be read.

Returns :

bool :

The value associated with the key option in section section.

getFloat(section, option)

Read a float value for a specified key in a specified section.

If the specified key does not exist, it will be added (adding the section, also, if necessary).

Parameters :

section : str

The section from which to read the value.

option : str

The key within section whose value should be read.

Returns :

float :

The value associated with the key option in section section.

getInt(section, option)

Read an integer value for a specified key in a specified section.

If the specified key does not exist, it will be added (adding the section, also, if necessary).

Parameters :

section : str

The section from which to read the value.

option : str

The key within section whose value should be read.

Returns :

int :

The value associated with the key option in section section.

getSpecial(section, option)

Read a more complicated structure associated with a specified key.

If the specified key does not exist, it will be added (adding the section, also, if necessary).

Parameters :

section : str

The section from which to read the value.

option : str

The key within section whose value should be read.

Returns :

variable :

The value associated with the key option in section section, passed through the eval function.

set(section, option, value, addSection=False)

Set the value of some key, and update the file accordingly.

Parameters :

section : str

The name of the section into which the value should be saved.

option : str

The key within section with which the value should be associated.

value : variable

The value which should be associated with the specified key.

addSection : bool

Whether to create the specified section before setting the value.

Returns :

variable :

The unchanged value of value.

AutoParser

class src.tools.old_config_parser.AutoParser(filename, defaults=None)

A configuration file parser which automatically loads sections.

Parameters :

filename : str

The absolute path of the configuration file.

Methods

getOptions(section)

Return a list of the options within a section.

Parameters :

section : str

The name of the section whose options should be returned.

Returns :

list of str :

The names of the options within the specified section.

getSections()

Return a list of the sections in the configuration file.

Returns :

list of str :

A list of strings, each of which is the title of a section in the configuration file.

hasSection(section)

Return whether the configuration file contains the named section.

Parameters :

section : str

The section for which to check.

Returns :

bool :

Whether the specified section exists in the configuration file.

loadSection(section)

Load the data from a section, converting to the correct types.

Parameters :

section : str

The name of the section from which to load the data.

Returns :

dict :

A dictionary in which the keys are the names of the options in the section, and the values are the values associated with the respective option. The type conversion understands strings, floats, integers, booleans (True, False, Yes, and No, case insensitive), None, and lists of these.

EvalParser

class src.tools.old_config_parser.EvalParser(configFile, defaults=None, preserveCase=True)

A configuration parser which uses eval and repr to deal with types.

Parameters :

configFile : str

The absolute path to the configuration file.

defaults : dict

A dictionary of default substitution parameters for the configuration file.

Methods

get(section, option, default=None)

Return the value associated with the specified option.

Parameters :

section : str

The section containing the option whose value is sought.

option : str

The option whose value is sought.

default : variant

The value to return if the requested section and option are not present in the file.

Returns :

variant :

The value associated with the requested key.

getOptions(section)

Return a list of options in a section of the configuration file.

Returns :

list of str :

A list containing the keys in a specified section of the configuration file.

getSections()

Return a list of section names in the configuration file.

Returns :

list of str :

A list containing the names of the sections in the configuration file.

set(section, option, value)

Set the value associated with a specified key in a specified section.

Functions

src.tools.old_config_parser.processValue(value)

Convert the loaded value to the correct type.

Parameters :

value : str

The value to parse.

Returns :

variable :

The input value converted to the appropriate type.

Table Of Contents

This Page