Generic configuration system using unrepr.
Configuration data may be supplied as a Python dictionary, as a filename, or as an open file object. When you supply a filename or file, Python’s builtin ConfigParser is used (with some extensions).
Configuration keys are separated into namespaces by the first ”.” in the key.
The only key that cannot exist in a namespace is the “environment” entry. This special entry ‘imports’ other config entries from a template stored in the Config.environments dict.
You can define your own namespaces to be called when new config is merged by adding a named handler to Config.namespaces. The name can be any string, and the handler must be either a callable or a context manager.
- class cherrypy.lib.reprconf.NamespaceSet¶
A dict of config namespace names and handlers.
Each config entry should begin with a namespace name; the corresponding namespace handler will be called once for each config entry in that namespace, and will be passed two arguments: the config key (with the namespace removed) and the config value.
Namespace handlers may be any Python callable; they may also be Python 2.5-style ‘context managers’, in which case their __enter__ method should return a callable to be used as the handler. See cherrypy.tools (the Toolbox class) for an example.
- class cherrypy.lib.reprconf.Config(file=None, **kwargs)¶
A dict-like set of configuration data, with defaults and namespaces.
May take a file, filename, or dict.
Reset self to default values.
Update self from a dict, file or filename.
Return a dict from ‘config’ whether it is a dict, file, or filename.
Return a Python object compiled from a string.
Load a module and retrieve a reference to that module.
Load a module and retrieve an attribute of that module.