1. cherrypy
  2. CherryPy
Issue #242 resolved

Added ability to specify methods in a config file

Anonymous created an issue

Currently, we have to add handler methods to the server programatically. With this patch, we can specify them in an ini file.br

One problem is that you can't specify a method alone --- it has to be qualified by at least one package (or possibly a class).br ie: {{{ configParam = myFunction # this should fail configParam = mypkg.myFunctinon # this should be fine }}}

Here is the diff: {{{ --- _cputil.py (revision 503) +++ _cputil.py (working copy) @@ -289,6 +289,21 @@ raise UnknownType('Add') return real+imag

  • def build_Getattr(self, o):
  • expressionList = []
  • expressionList.append(o.attrname)
  • expression = o
  • while not expression.expr.class.name == 'Name':
  • expression = expression.expr
  • expressionList.append(expression.attrname)
  • expressionList.append(expression.expr.name)
  • expressionList.reverse()
  • method = expressionList[-1]
  • mod = import(expressionList[0])
  • for comp in expressionList[1:-1]:
  • mod = getattr(mod, comp)
  • return getattr(mod, method) + def unrepr(s): if not s: return s }}}

Reported by miles@phgroup.com

Comments (2)

  1. Robert Brewer

    Partially fixed in changeset [521]. The build_Getattr method is now in place, at least. Sylvain and I agreed that this is as far as this ticket should go--that is, CP shouldn't explicitly facilitate specifying page methods in the config file; the config should not become an all-inclusive way to avoid coding. So those who wish to do so will have to manually grab such config values and bind them to cherrypy.root on their own initiative.

    But it was good to provide getattr handling for unrepr regardless.

  2. Log in to comment