Issue #1033 resolved

Create a sensible decorator for _cp_dispatch

Anonymous created an issue

Since _cp_config has a decorator, and _cp_dispatch follows that naming trend, a sensible decorator (possibly a class decorator) that is a shortcut for dispatch's most common use case would be a good idea.

One issue with class decorators is that they are Py3k only; however, the decorator could perhaps be polymorphic (like cherrypy.expose), also allowing:

class Test: _cp_dispatch = cherrypy.dispatch_decorator('hi')

The decorator / default dispatch handler should probably just pop the first vpath element to a specified request parameter name ('hi' above), then return getattr(self, vpath[0], None) to resume normal object traversal (note that the next token vpath[0] is popped after returning).

Possible decorator names: cherrypy.dispatch, ... cherrypy.url_parameter, cherrypy.parameter? Maybe? Just thinking aloud.

Reported by

Comments (5)

  1. Anonymous

    One update - fumanchu pointed out that /users/326 should be a valid URI, so it should be verified that index() and default() are called correctly.

  2. Anonymous

    Update from the wonderful mind of fumanchu: @cherrypy.popargs('year', 'month', 'day').

    Allow multiple specifications in a single decorator, and popargs is a pretty good name...

  3. Anonymous

    This has been implemented in Py3k revision 2710.

    One other change to the above recommendations - the decorator can optionally accept a handler= keyword parameter, which optionally specifies an object that handles the rest of the path (if unspecified, "self" is expected to handle it).

  4. Log in to comment