cherrypy.lib.reprconf module

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.

class cherrypy.lib.reprconf.Config(file=None, **kwargs)[source]

Bases: dict

A dict-like set of configuration data, with defaults and namespaces.

May take a file, filename, or dict.

_apply(config)[source]

Update self from a dict.

defaults = {}
environments = {}
namespaces = {'checker': <function <lambda>>, 'engine': <function _engine_namespace_handler>, 'log': <function <lambda>>, 'server': <function _server_namespace_handler>, 'tree': <function _tree_namespace_handler>}
reset()[source]

Reset self to default values.

update(config)[source]

Update self from a dict, file, or filename.

class cherrypy.lib.reprconf.NamespaceSet[source]

Bases: dict

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

copy() → a shallow copy of D
class cherrypy.lib.reprconf.Parser(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>, converters=<object object>)[source]

Bases: configparser.ConfigParser

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

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 48
_abc_registry = <_weakrefset.WeakSet object>
as_dict(raw=False, vars=None)[source]

Convert an INI file to a dictionary

dict_from_file(file)[source]
classmethod load(input)[source]

Resolve ‘input’ to dict from a dict, file, or filename.

optionxform(optionstr)[source]
read(filenames)[source]

Read and parse a filename or an iterable of filenames.

Files that cannot be opened are silently ignored; this is designed so that you can specify an iterable of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the iterable will be read. A single filename may also be given.

Return list of successfully read files.

class cherrypy.lib.reprconf._Builder[source]

Bases: object

_build_call35(o)[source]

Workaround for python 3.5 _ast.Call signature, docs found here https://greentreesnakes.readthedocs.org/en/latest/nodes.html

astnode(s)[source]

Return a Python3 ast Node compiled from a string.

build(o)[source]
build_Add(o)[source]
build_Attribute(o)[source]
build_BinOp(o)[source]
build_Call(o)[source]
build_Constant(o)
build_Dict(o)[source]
build_Index(o)[source]
build_List(o)[source]
build_Mult(o)[source]
build_Name(o)[source]
build_NameConstant(o)[source]
build_NoneType(o)[source]
build_Num(o)[source]
build_Str(o)[source]
build_Subscript(o)[source]
build_Tuple(o)[source]
build_USub(o)[source]
build_UnaryOp(o)[source]
cherrypy.lib.reprconf.attributes(full_attribute_name)[source]

Load a module and retrieve an attribute of that module.

cherrypy.lib.reprconf.modules(modulePath)[source]

Load a module and retrieve a reference to that module.

cherrypy.lib.reprconf.unrepr(s)[source]

Return a Python object compiled from a string.