Ticket #242 (enhancement)
Opened 3 years ago
Last modified 3 years ago
Added ability to specify methods in a config file
Status: closed (fixed)
| Reported by: | miles@phgroup.com | Assigned to: | rdelon |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.1 |
| Component: | CherryPy code | Keywords: | |
| Cc: |
Currently, we have to add handler methods to the server programatically. With this patch, we can specify them in an ini file.
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).
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
Change History
08/08/05 13:41:38: Modified by fumanchu
- status changed from new to closed.
- resolution set to fixed.


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.