plainbox.impl.config – configuration

Warning

THIS MODULE DOES NOT HAVE A STABLE PUBLIC API

class plainbox.impl.secure.config.ChoiceValidator(choice_list)[source]

A validator ensuring that values are in a given set

class plainbox.impl.secure.config.Config[source]

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()
class Meta
section_list = []
variable_list = []
Config.filename_list[source]

list of pathnames to files that were loaded by the last call to read()

classmethod Config.get()[source]

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
Config.get_parser_obj()[source]

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.

Config.problem_list[source]

list of ValidationError that were detected by the last call to read()

Config.read(filename_list)[source]

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.

Config.read_string(string)[source]

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.

Config.validate_whole()[source]

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.

Config.write(stream)[source]

Write configuration data to a stream.

Parameters:stream – a file-like object that can be written to.

This method recreates the content of all the configuration variables in a manner that can be subsequently read back.

class plainbox.impl.secure.config.ConfigMeta[source]

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 plainbox.impl.secure.config.ConfigMetaData[source]

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()
filename_list = []
section_list = []
variable_list = []
class plainbox.impl.secure.config.INameTracking[source]

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.

class plainbox.impl.secure.config.IValidator[source]

An interface for variable vale validators

plainbox.impl.secure.config.KindValidator(variable, new_value)[source]

A validator ensuring that values match the “kind” of the variable.

class plainbox.impl.secure.config.NotEmptyValidator(msg=None)[source]

A validator ensuring that values aren’t empty

class plainbox.impl.secure.config.NotUnsetValidator(msg=None)[source]

A validator ensuring that values are set

..note::
Due to the way validators work this validator must be the first one in any validator list in order to work. Otherwise the implicit KindValidator() will take precedence and the check will most likely fail as None or Unset are not of the expected type of the configuration variable being worked with.
understands_Unset = True
class plainbox.impl.secure.config.PatternValidator(pattern_text)[source]

A validator ensuring that values match a given pattern

class plainbox.impl.secure.config.PlainBoxConfigParser(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object at 0x2b4afa931090>)[source]

A subclass of ConfigParser with the following changes:

  • option names are not lower-cased
  • write() has deterministic ordering (sorted by name)
optionxform(option)[source]

Overridden method from configparser.ConfigParser.

Returns option without any transformations

write(fp, space_around_delimiters=True)[source]

Write an .ini-format representation of the configuration state.

If space_around_delimiters is True (the default), delimiters between keys and values are surrounded by spaces. The ordering of section and values within is deterministic.

plainbox.impl.secure.config.Section[source]

A section of a configuration file.

class plainbox.impl.secure.config.UnsetType[source]

Class of the Unset object

exception plainbox.impl.secure.config.ValidationError(variable, new_value, message)[source]

Exception raised when configuration variables fail to validate

plainbox.impl.secure.config.Variable[source]

Variable that can be used in a configuration systems

plainbox.impl.secure.config.understands_Unset(cls_or_func)[source]

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.

Previous topic

plainbox.impl.secure – code for external (trusted) launchers

Next topic

plainbox.impl.secure.job – secure code for job definitions

This Page