Issue #487 resolved

Config keys are not introspectable

Robert Brewer
created an issue

CherryPy has recently been touted as [http://blog.dowski.com/2006/03/05/cherrypy-and-the-interactive-interpreter/ easy to mess around with from within the interactive interpreter]. This is a direct side-effect of CherryPy's re-use of existing Python idioms for startup and shutdown, handler dispatch, redirection, etc.

One facet of CherryPy which does not follow this "Pythonic" design style is the config module. Configs are stored in a flat dictionary, and re-invent (in a very limited way) the object heirarchy via "component.setting" syntax in strings. Since these config entries may simply not be present, they are not introspectable, and require the poor user to rely either on perfect docs (which are not CP's strong point yet), or on reading the source code. This is a significant barrier to entry for new users, and even for experienced users who are exploring any functionality which they have not used before.

This could be remedied by separating the OO configuration settings from the "logic which parses configs declared in a file". That is, rather than make the settings behave like a config file, they should be declared and behave in a more expressive, object-oriented style; CP would then provide a tool to transform/apply a configfile to that.

Comments (5)

  1. michele

    I don't get every point you're talking about here since I'm not so prepared regarding CP internals. :-(

    Anyway have you considered using configobj to manage config files? Kevin is using it inside TG, you can even bundle it with CP since it's only one file or two files with validation stuffs, it maps a config INI file to python.

    http://www.voidspace.org.uk/python/configobj.html

    "ConfigObj has no external dependencies. This file is sufficient to access all the functionality except Validation."

  2. Robert Brewer reporter

    I'm working on an approach where config is inspected once during tool_up, and various entries are bound at that point as attributes directly on the Request and Response objects. See attached reqconf.patch for the first few settings.

  3. Robert Brewer reporter

    Fixed in [1271], [1275], and [1278]. Config is now used to set attributes on cherrypy.engine, server, request, response, and log. So config.get is pretty much obsolete.

  4. Log in to comment