configoose.protocol package
Submodules
configoose.protocol.abc module
- class configoose.protocol.abc.Protocol
Bases:
ABCAbstract base class for protocol classes
Informally speaking, a protocol is a manner of handling a certain type of configuration data, for example configuration in json or toml or ini or a python file etc. Client code chooses the protocol that it wants to handle its configuration data.
A protocol class is essentially defined by its run() method which takes the text of the configuration as argument.
New protocols can be added by defining new subclasses of
Protocol. In particular, several protocol classes can be defined to handle the same configuration data.- abstract run(app: AddedProtocol, preamble: Preamble, text: str, med: Mediator)
Configure a module according to this protocol
- Parameters:
ap – the
AddedProtocolinstance passed by the configurator. Enables access to a handler function defined by the client code.preamble – the preamble extracted from the configuration
text – the text read from the configuration (without the preamble)
med – the Mediator instance used to access the configuration
- classmethod template_text() str
Return a basic template configuration for this protocol (without preamble)
This is intended to give users a starting point when they write a configuration file for this protocol.
- Returns:
a string usable as basic configuration for this protocol
- Return type:
str
The default implementation returns an empty string.
configoose.protocol.configparser module
- class configoose.protocol.configparser.Protocol
Bases:
ProtocolProtocol to handle configurations in Python’s configparser format
Running this protocol creates a ConfigParser instance that parses the configuration text, then it calls a handler method if the client code has registered one. It passes three arguments to the handler method:
the
AddedProtocolinstance that was registered by the configuratorthe
Preambleextracted from the configuration filethe
ConfigParserinstance used to parse the configuration.
- run(ap, preamble, text, med)
Configure a module according to this protocol
- Parameters:
ap – the
AddedProtocolinstance passed by the configurator. Enables access to a handler function defined by the client code.preamble – the preamble extracted from the configuration
text – the text read from the configuration (without the preamble)
med – the Mediator instance used to access the configuration
- classmethod template_text()
Return a basic template configuration for this protocol (without preamble)
This is intended to give users a starting point when they write a configuration file for this protocol.
- Returns:
a string usable as basic configuration for this protocol
- Return type:
str
The default implementation returns an empty string.
configoose.protocol.iterative module
- class configoose.protocol.iterative.Protocol
Bases:
ProtocolThe iterative protocol is an experimental configuration protocol
Like the methodic protocol, it is based on configuration files containing Python code. These configuration files must define a generator function named iconfigure() which generates a sequence of configuration items, such as small dictionaries for exemple. For each item, the protocol calls the handler function provided by client code with three arguments
The
AddedProtocolinstance given by the configurator.The
Preambleextracted from the configuration fileThe generated configuration item.
- run(ap, preamble, text, med)
Configure a module according to this protocol
- Parameters:
ap – the
AddedProtocolinstance passed by the configurator. Enables access to a handler function defined by the client code.preamble – the preamble extracted from the configuration
text – the text read from the configuration (without the preamble)
med – the Mediator instance used to access the configuration
- classmethod template_text()
Return a basic template configuration for this protocol (without preamble)
This is intended to give users a starting point when they write a configuration file for this protocol.
- Returns:
a string usable as basic configuration for this protocol
- Return type:
str
The default implementation returns an empty string.
configoose.protocol.methodic module
- exception configoose.protocol.methodic.Error
Bases:
Exception
- class configoose.protocol.methodic.Protocol
Bases:
ProtocolThe methodic protocol, a type of Python configuration
The methodic protocol expects a Python configuration file containing a configure() function with a simple handler argument. A handler instance is created by calling the handler function (or class) registered by the configurator, with arguments
The
AddedProtocolinstance given by the configuratorThe
Preambleextracted from the configuration file
The configuration text is executed by Python and the configure() function is called. It is the responsibility of the configuration file to call methods of the handler object in its configure() function.
The configoose module itself is configured with the methodic protocol, thus the contents of the configooseconf module is an example of how to configure a file with this protocol.
- run(ap, preamble, text, med)
Configure a module according to this protocol
- Parameters:
ap – the
AddedProtocolinstance passed by the configurator. Enables access to a handler function defined by the client code.preamble – the preamble extracted from the configuration
text – the text read from the configuration (without the preamble)
med – the Mediator instance used to access the configuration
- classmethod template_text()
Return a basic template configuration for this protocol (without preamble)
This is intended to give users a starting point when they write a configuration file for this protocol.
- Returns:
a string usable as basic configuration for this protocol
- Return type:
str
The default implementation returns an empty string.
configoose.protocol.raw module
- class configoose.protocol.raw.Protocol
Bases:
ProtocolProtocol to handle configurations in raw format
Running this protocol calls a handler method if the client code has registered one. The arguments passed to the handler method are
the
AddedProtocolinstance that was registered by the configuratorthe
Preambleextracted from the configuration filethe text contained in the configuration
the
Mediatorinstance used to access the configuration
- run(ap, preamble, text, med)
Configure a module according to this protocol
- Parameters:
ap – the
AddedProtocolinstance passed by the configurator. Enables access to a handler function defined by the client code.preamble – the preamble extracted from the configuration
text – the text read from the configuration (without the preamble)
med – the Mediator instance used to access the configuration