New tools for parsing configuration files.
A class to parse configuration files in a variety of ways.
Parameters : | filePath : string
fileFormat : int
substitutions : dict
defaultValues : dict
preserveCase : bool
|
---|
Methods
Read a value from the configuration file.
Attempt to read a value from the configuration file under the section section and associated with the key option. If either of these is missing from the file, search the dictionary of default values. If either the section or the key is missing from that dictionary, also, return default.
If the file format is FORMAT_BASIC and the requested item is found in the file, return the string from the file, passed through converter if it is specified.
If the file format is FORMAT_REPR and the requested item is found in the file, return the value from the file, passed first through eval and then, if it is specified, through converter.
If the file format is FORMAT_AUTO and the requested item is found in the file, attempt to guess the type of the data in the file, cast the data to that type, and return it, passing it through converter if it is specified.
If the requested data is not found in the file, return the appropriate element from the dictionary of default values, passed through converter if it is specified.
If the requested data is not found in either the file or the defaults dictionary, return default, passed through converter if it is specified.
Finally, after any/all conversions have taken place, write the value that will be returned to the configuration file and return said value.
Parameters : | section : string
option : string
default : (variant)
converter : function
|
---|---|
Returns : | (variant) :
|
Return a value from the configuration file as a boolean.
Parameters : | section : string
option : string
default : bool
|
---|---|
Returns : | bool :
|
Return a value from the configuration file as a float.
Parameters : | section : string
option : string
default : float
|
---|---|
Returns : | int :
|
Return a value from the configuration file as an integer.
Parameters : | section : string
option : string
default : int
|
---|---|
Returns : | int :
|
Return a list of options under a specified section.
Return a list of strings specifying the keys contained within a specified section, including the information from both the defaults dictionary and the configuration file. Each option will occur only once.
Parameters : | section : str
|
---|---|
Returns : | list of str :
|
Return a dictionary containing the options and values in a section.
Parameters : | section : str
|
---|---|
Returns : | dict :
|
Return a list of available sections.
Returns : | list of str :
|
---|
Write a value to the configuration file.
If the file format is FORMAT_REPR, pass value through the repr function before writing it.
Parameters : | section : str
option : str
value : (variant)
|
---|