j2labs/brubeck — Issue #49: Pass **kwargs to handlers instead of *args for better use of groups in routing regex
Author: sethmurphy
Created: 2011-12-09 17:42:39+00:00
State: open

In defining regex routes the groups may be named, but the arguments are always passed to the handler in the order received, therefore the method signature must match the order, not the names of the groups.

This causes complications when relying on using `prepare()` for authentication when arguments from the URL are needed. An example of this is a request for access to a chat channel where the RESTfull URL pattern is:

` r'^/api/login/(?P.+)/(?P.+)$'.`

This means for this route the `prepare()` logic, when accessing `self._url_args`, must always assume the first and second groups are always channel_id, nickname. All other routes for the handler would need to conform to this pattern. In this simple example the pattern does not pose a problem, yet if I wanted to use the same `prepare()` in a subclass for authentication for many handlers it would be difficult.

This change may cause a slight performance hit, and I could re-parse the route in `prepare()` and use accordingly. However, using **kwds would be much more flexible. I would be willing to submit a pull request for this if needed.