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

  Bases: `dict`

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

  May take a file, filename, or dict.

  _apply(config)

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

    Reset self to default values.

  update(config)

    Update self from a dict, file, or filename.

class cherrypy.lib.reprconf.NamespaceSet

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

    Return a shallow copy of the dict.

class cherrypy.lib.reprconf.Parser(defaults=None, dict_type=<class 'dict'>, 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>, allow_unnamed_section=False)

  Bases: `ConfigParser`

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

  _abc_impl = <_abc._abc_data object>
  as_dict(raw=False, vars=None)

    Convert an INI file to a dictionary.

  dict_from_file(file)
  classmethod load(input)

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

  optionxform(optionstr)
  read(filenames)

    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

  Bases: `object`

  _build_call35(o)

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

  astnode(s)

    Return a Python3 ast Node compiled from a string.

  build(o)
  build_Add(o)
  build_Attribute(o)
  build_BinOp(o)
  build_Call(o)
  build_Constant(o)
  build_Dict(o)
  build_Index(o)
  build_List(o)
  build_Mult(o)
  build_Name(o)
  build_NameConstant(o)
  build_NoneType(o)
  build_Num(o)
  build_Str(o)
  build_Subscript(o)
  build_Tuple(o)
  build_USub(o)
  build_UnaryOp(o)

cherrypy.lib.reprconf.attributes(full_attribute_name)

  Load a module and retrieve an attribute of that module.

cherrypy.lib.reprconf.modules(modulePath)

  Load a module and retrieve a reference to that module.

cherrypy.lib.reprconf.unrepr(s)

  Return a Python object compiled from a string.