Allow users to pass callables in as controllers, not just import paths
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 8 Apr 2012 14:54:32 +0000 (09:54 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 8 Apr 2012 14:54:32 +0000 (09:54 -0500)
mediagoblin/app.py

index b7ca092d2345b32d42188261059cb251ae681482..99c7de76b4a5809ea8b3eb7d00513c64857fe8ab 100644 (file)
@@ -167,7 +167,13 @@ class MediaGoblinApp(object):
             request.matchdict = {}  # in case our template expects it
             return render_404(request)(environ, start_response)
 
-        controller = common.import_component(route_match['controller'])
+        # import the controller, or if it's already a callable, call that
+        route_controller = route_match['controller']
+        if isinstance(route_controller, unicode) \
+                or isinstance(route_controller, str):
+            controller = common.import_component(route_match['controller'])
+        else:
+            controller = route_match['controller']
 
         # pass the request through our meddleware classes
         for m in self.meddleware: