Commits

Sylvain Hellegouarch committed 93a68bf

The RoutesDispatcher now accepts an extra parameter. If it sets to False (default) the controller and action keys from the Routes matching result dictionary will be removed. If it sets to True they will be kept. In the first case the page handlers will be passed on only the parameters as the default CP dispatcher.

  • Participants
  • Parent commits 66d6c62

Comments (0)

Files changed (1)

cherrypy/_cpdispatch.py

 class RoutesDispatcher(object):
     """A Routes based dispatcher for CherryPy."""
     
-    def __init__(self):
+    def __init__(self, full_result=False):
+        """
+        Routes dispatcher
+
+        Set full_result to True if you wish the controller
+        and the action to be passed on to the page handler
+        parameters. By default they won't be.
+        """
         import routes
+        self.full_result = full_result
         self.controllers = {}
         self.mapper = routes.Mapper()
         self.mapper.controller_scan = self.controllers.keys
         
         result = self.mapper.match(path_info)
         config.mapper_dict = result
-        request.params.update(result or {})
+        params = {}
+        if result:
+            params = result.copy()
+        if not self.full_result:
+            params.pop('controller', None)
+            params.pop('action', None)
+        request.params.update(params)
         
         # Get config for the root object/path.
         request.config = base = cherrypy.config.copy()
         else:
             last = None
         for atom in atoms:
-            curpath = "/".join((curpath, name))
+            curpath = "/".join((curpath, atom))
             if curpath in app.config:
                 merge(app.config[curpath])