Warning
THIS MODULE DOES NOT HAVE A STABLE PUBLIC API
Bases: plainbox.impl.secure.config.IValidator
A validator ensuring that values are in a given set
Bases: builtins.object
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() |
Bases: plainbox.impl.secure.config.ConfigMetaData
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.
Bases: builtins.type
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
return a type’s method resolution order
Bases: builtins.object
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() |
Bases: builtins.object
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.
Bases: builtins.object
An interface for variable vale validators
A validator ensuring that values match the “kind” of the variable.
Bases: plainbox.impl.secure.config.IValidator
A validator ensuring that values aren’t empty
Bases: plainbox.impl.secure.config.IValidator
A validator ensuring that values are set
Bases: plainbox.impl.secure.config.IValidator
A validator ensuring that values match a given pattern
Bases: configparser.ConfigParser
A subclass of ConfigParser with the following changes:
Create a new section in the configuration. Extends RawConfigParser.add_section by validating if the section name is a string.
Get an option value for a given section.
If `vars’ is provided, it must be a dictionary. The option is looked up in `vars’ (if provided), `section’, and in `DEFAULTSECT’ in that order. If the key is not found and `fallback’ is provided, it is used as a fallback value. `None’ can be provided as a `fallback’ value.
If interpolation is enabled and the optional argument `raw’ is False, all interpolations are expanded in the return values.
Arguments `raw’, `vars’, and `fallback’ are keyword only.
The section DEFAULT is special.
Check for the existence of a given option in a given section. If the specified `section’ is None or an empty string, DEFAULT is assumed. If the specified `section’ does not exist, returns False.
Indicate whether the named section is present in the configuration.
The DEFAULT section is not acknowledged.
Return a list of (name, value) tuples for each option in a section.
All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument `raw’ is true. Additional substitutions may be provided using the `vars’ argument, which must be a dictionary whose contents overrides any pre-existing defaults.
The section DEFAULT is special.
Return a list of option names for the given section name.
Overridden method from configparser.ConfigParser.
Returns option without any transformations
If key is not found, d is returned if given, otherwise KeyError is raised.
Remove a section from the parser and return it as a (section_name, section_proxy) tuple. If no section is present, raise KeyError.
The section DEFAULT is never returned because it cannot be removed.
Read and parse a filename or a list of filenames.
Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given.
Return list of successfully read files.
Read configuration from a dictionary.
Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order.
All types held in the dictionary are converted to strings during reading, including section names, option names and keys.
Optional second argument is the `source’ specifying the name of the dictionary being read.
Like read() but the argument must be a file-like object.
The `f’ argument must be iterable, returning one line at a time. Optional second argument is the `source’ specifying the name of the file being read. If not given, it is taken from f.name. If `f’ has no `name’ attribute, `<???>’ is used.
Read configuration from a given string.
Deprecated, use read_file instead.
Remove an option.
Remove a file section.
Return a list of section names, excluding [DEFAULT]
Set an option. Extends RawConfigParser.set by validating type and interpolation syntax on the value.
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
Bases: builtins.object
Class of the Unset object
Bases: builtins.ValueError
Exception raised when configuration variables fail to validate
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
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.