cherrypy.lib.reprconf

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).

Namespaces

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.

Classes

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()

Reset self to default values.

update(config)

Update self from a dict, file or filename.

class cherrypy.lib.reprconf.Parser(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False)

Sub-class of ConfigParser that keeps the case of options and that raises an exception if the file cannot be read.

as_dict(raw=False, vars=None)

Convert an INI file to a dictionary

Functions

cherrypy.lib.reprconf.as_dict(config)

Return a dict from ‘config’ whether it is a dict, file, or filename.

cherrypy.lib.reprconf.unrepr(s)

Return a Python object compiled from a string.

cherrypy.lib.reprconf.modules(modulePath)

Load a module and retrieve a reference to that module.

cherrypy.lib.reprconf.attributes(full_attribute_name)

Load a module and retrieve an attribute of that module.