aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/routing.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tools/routing.py')
-rw-r--r--mediagoblin/tools/routing.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/mediagoblin/tools/routing.py b/mediagoblin/tools/routing.py
index 6c5acbec..791cd1e6 100644
--- a/mediagoblin/tools/routing.py
+++ b/mediagoblin/tools/routing.py
@@ -24,18 +24,28 @@ _log = logging.getLogger(__name__)
url_map = Map()
-view_functions = {}
+class MGRoute(Rule):
+ def __init__(self, endpoint, url, controller):
+ Rule.__init__(self, url, endpoint=endpoint)
+ self.gmg_controller = controller
-def endpoint_to_controller(endpoint):
- view_func = view_functions[endpoint]
+ def empty(self):
+ new_rule = Rule.empty(self)
+ new_rule.gmg_controller = self.gmg_controller
+ return new_rule
+
+
+def endpoint_to_controller(rule):
+ endpoint = rule.endpoint
+ view_func = rule.gmg_controller
_log.debug('endpoint: {0} view_func: {1}'.format(endpoint, view_func))
# import the endpoint, or if it's already a callable, call that
if isinstance(view_func, basestring):
view_func = import_component(view_func)
- view_functions[endpoint] = view_func
+ rule.gmg_controller = view_func
return view_func
@@ -44,14 +54,7 @@ def add_route(endpoint, url, controller):
"""
Add a route to the url mapping
"""
- # XXX: We cannot use this, since running tests means that the plugin
- # routes will be populated over and over over the same session.
- #
- # assert endpoint not in view_functions.keys(), 'Trying to overwrite a rule'
-
- view_functions.update({endpoint: controller})
-
- url_map.add(Rule(url, endpoint=endpoint))
+ url_map.add(MGRoute(endpoint, url, controller))
def mount(mountpoint, routes):