RawConfigParser
The RawConfigParser class is accessible via the initools.configparser module.
Attributes
Methods
f __init__(self, defaults=None, encoding=<class initools.configparser._NoDefault at 0xb74e7ddc>, percent_expand=<class initools.configparser._NoDefault at 0xb74e7ddc>, safe_set=<class initools.configparser._NoDefault at 0xb74e7ddc>, dollar_expand=<class initools.configparser._NoDefault at 0xb74e7ddc>, case_sensitive=<class initools.configparser._NoDefault at 0xb74e7ddc>, section_case_sensitive=<class initools.configparser._NoDefault at 0xb74e7ddc>, global_section=<class initools.configparser._NoDefault at 0xb74e7ddc>, inline_comments=<class initools.configparser._NoDefault at 0xb74e7ddc>, inherit_defaults=<class initools.configparser._NoDefault at 0xb74e7ddc>, extendable=<class initools.configparser._NoDefault at 0xb74e7ddc>) ...
f add_section(self, section, comment=None) ...
Add a section named section to the instance.
If a section by the given name already exists, DuplicateSectionError is raised.
f has_section(self, section) ...
Indicates whether the named section is present in the configuration.
The DEFAULT section is not acknowledged.
f has_option(self, section, option) ...
If the given section exists, and contains the given option, return True; otherwise return False.
f read(self, filenames, extending=False, map_sections=None) ...
Attempt to read and parse a list of filenames, returning a list of filenames which were successfully parsed.
If filenames is a string or Unicode string, it is treated as a single filename. If a file named in filenames cannot be opened, that file will be ignored. This is designed so that you can specify a list of potential configuration file locations (for example, the current directory, the user's home directory, and some system-wide directory), and all existing configuration files in the list will be read. If none of the named files exist, the ConfigParser instance will contain an empty dataset. An application which requires initial values to be loaded from a file should load the required file or files using readfp() before calling read() for any optional files:
import ConfigParser, os
config = ConfigParser.ConfigParser() config.readfp(open('defaults.cfg')) config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
If extending is true (default false) then the values picked up from the file will not override the values already present (that means that the file being loaded is extended by the already loaded file).
f readfp(self, fp, filename='<???>', extending=False, map_sections=None) ...
Read and parse configuration data from the file or file-like object in fp
Only the readline() method is used. If filename is omitted and fp has a name attribute, that is used for filename; the default is '<???>'.
f get(self, section, option, raw=False, vars=None, _recursion=0) ...
Get an option value for the named section.
If self.percent_expand is true, then all the '%' interpolations are expanded, using the optional vars. If raw is True, then no interpolation is done.
f getint(self, section, option) ...
A convenience method which coerces the option in the specified section to an integer.
f getfloat(self, section, option) ...
A convenience method which coerces the option in the specified section to a floating point number.
f getboolean(self, section, option) ...
A convenience method which coerces the option in the specified section to a Boolean value.
Note that the accepted values for the option are "1", "yes", "true", and "on", which cause this method to return True, and "0", "no", "false", and "off", which cause it to return False. These string values are checked in a case-insensitive manner. Any other value will cause it to raise ValueError.
f getfilename(self, section, option) ...
Returns the value of the option, interpreted as a filename relative to the location of where the option was defined.
Raises a ValueError if the option doesn't have an associated filename and the path is not absolute.
f items(self, section, raw=False, vars=None) ...
Return a list of (name, value) pairs for each option in the given section.
If self.percent_expand is true, then all the '%' interpolations are expanded, using the optional vars. If raw is True, then no interpolation is done.
f set(self, section, option, value, filename=None, line_number=None, comments=None) ...
If the given section exists, set the given option to the specified value; otherwise raise NoSectionError.
While it is possible to use RawConfigParser (or ConfigParser with raw parameters set to true) for internal storage of non-string values, full functionality (including interpolation and output to files) can only be achieved using string values.
If self.safe_set is true, then only string values will be allowed.
f write(self, fileobject) ...
Write a representation of the configuration to the specified file object.
This representation can be parsed by a future read() call.
f remove_option(self, section, option) ...
Remove the specified option from the specified section.
If the section does not exist, raise NoSectionError. If the option existed to be removed, return True; otherwise return False.
f remove_section(self, section) ...
Remove the specified section from the configuration.
If the section in fact existed, return True. Otherwise return False.
f optionxform(self, option) ...
Transforms the option name option as found in an input file or as passed in by client code to the form that should be used in the internal structures.
The default implementation returns a lower-case version of option; subclasses may override this or client code can set an attribute of this name on instances to affect this behavior. Setting this to str(), for example, would make option names case sensitive.
f sectionxform(self, option) ...
Transforms the section name option as found in an input file or as passed in by client code to the form that should be used in the internal structures.
The default implementation returns a lower-case version of option; subclasses may override this or client code can set an attribute of this name on instances to affect this behavior. Setting this to str(), for example, would make option names case sensitive.
See the source for more information.