Warning
THIS MODULE DOES NOT HAVE A STABLE PUBLIC API
A validator ensuring that values are in a given set
Base class for configuration systems
Attr _var: | storage backend for Variable definitions |
---|---|
Attr _section: | storage backend for Section definitions |
Attr _filename_list: | |
list of pathnames to files that were loaded by the last call to read() | |
Attr _problem_list: | |
list of ValidationError that were detected by the last call to read() |
list of pathnames to files that were loaded by the last call to read()
Get an instance of this Config class with all the configuration loaded from default locations. The locations are determined by Meta.filename_list attribute.
Returns: | fresh Config instance |
---|
Get a ConfigParser-like object with the same data.
Returns: | A PlainBoxConfigParser object with all of the data copied from this Config object. |
---|
Since PlainBoxConfigParser is a subclass of configparser.ConfigParser it has a number of useful utility methods. By using this function one can obtain a ConfigParser-like object and work with it directly.
list of ValidationError that were detected by the last call to read()
Load and merge settings from many files.
This method tries to open each file from the list of filenames, parse it as an INI file using PlainBoxConfigParser (a simple ConfigParser subclass that respects the case of key names). The list of files actually accessed is saved as available as Config.filename_list.
If any problem is detected during parsing (e.g. syntax errors) those are captured and added to the Config.problem_list.
After all files are loaded each Variable and Section defined in the Config class is assigned with the data from the merged configuration data.
Any variables that cannot be assigned and raise ValidationError are ignored but the list of problems is saved.
All unused configuration (extra variables that are not defined as either Variable or Section class) is silently ignored.
Note
This method resets _problem_list and _filename_list.
Load settings from a string.
Parameters: | string – The full text of INI-like configuration to parse and apply |
---|
This method parses the string as an INI file using PlainBoxConfigParser (a simple ConfigParser subclass that respects the case of key names).
If any problem is detected during parsing (e.g. syntax errors) those are captured and added to the Config.problem_list.
After parsing the string each Variable and Section defined in the Config class is assigned with the data from the configuration data.
Any variables that cannot be assigned and raise ValidationError are ignored but the list of problems is saved.
All unused configuration (extra variables that are not defined as either Variable or Section class) is silently ignored.
Note
This method resets _problem_list and _filename_list.
Validate the whole configuration object.
This method may be overridden to provide whole-configuration validation. It is especially useful in cases when a pair or more of variables need to be validated together to be meaningful.
The default implementation does nothing. Other implementations may raise ValidationError.
Meta class for all configuration classes.
This meta class handles assignment of ‘_name’ attribute to each Variable instance created in the class body.
It also accumulates such instances and assigns them to variable_list in a helper Meta class which is assigned back to the namespace
Class containing meta-data about a Config class
Sub-classes of this class are automatically added to each Config subclass as a Meta class-level attribute.
This class has typically two attributes:
Attr variable_list: | |
---|---|
A list of all Variable objects defined in the class | |
Attr section_list: | |
A list of all Section object defined in the class | |
Attr filename_list: | |
A list of config files (pathnames) to read on call to Config.read() |
Interface for classes that are instantiated as a part of definition of another class. The purpose of this interface is to allow instances to learn about the name (python identifier) that was assigned to the instance at class definition time.
Subclasses must define the _set_tracked_name() method.
A validator ensuring that values match the “kind” of the variable.
A validator ensuring that values aren’t empty
A validator ensuring that values are set
A validator ensuring that values match a given pattern
A subclass of ConfigParser with the following changes:
Exception raised when configuration variables fail to validate
Decorator for marking validators as supporting the special Unset value.
This decorator should be applied to every validator that natively supports Unset values. Without it, Unset is never validated.
This decorator works by setting the understands_Unset attribute on the decorated object and returning it intact.