Commits

Robert Brewer committed 8d8f1c5

Moved merge out of {{{Application.__init__}}} so custom namespaces can be defined per-app. Also allow Tree.mount to accept an Application instance (instead of a root which gets wrapped in an Application).

Comments (0)

Files changed (1)

cherrypy/_cptree.py

         a dict of {key: value} pairs.
     """
     
-    def __init__(self, root, script_name="", conf=None):
+    def __init__(self, root, script_name=""):
         self.log = _cplogging.LogManager(id(self))
         self.root = root
         self.script_name = script_name
         self.namespaces = {"log": lambda k, v: setattr(self.log, k, v),
                            }
         self.conf = {}
-        if conf:
-            self.merge(conf)
     
     def _get_script_name(self):
         if self._script_name is None:
         """Merge the given config into self.config."""
         _cpconfig.merge(self.conf, conf)
         
-        # Create log handlers as specified in config.
+        # Handle namespaces specified in config.
         rootconf = self.conf.get("/", {})
         for k, v in rootconf.iteritems():
             atoms = k.split(".", 1)
         """Mount a new app from a root object, script_name, and conf."""
         # Next line both 1) strips trailing slash and 2) maps "/" -> "".
         script_name = script_name.rstrip("/")
-        app = Application(root, script_name, conf)
+        
+        if isinstance(root, Application):
+            app = root
+        else:
+            app = Application(root, script_name)
+            
+            # If mounted at "", add favicon.ico
+            if script_name == "" and root and not hasattr(root, "favicon_ico"):
+                import os
+                from cherrypy import tools
+                favicon = os.path.join(os.getcwd(), os.path.dirname(__file__),
+                                       "favicon.ico")
+                root.favicon_ico = tools.staticfile.handler(favicon)
+        
+        if conf:
+            app.merge(conf)
+        
         self.apps[script_name] = app
         
-        # If mounted at "", add favicon.ico
-        if script_name == "" and root and not hasattr(root, "favicon_ico"):
-            import os
-            from cherrypy import tools
-            favicon = os.path.join(os.getcwd(), os.path.dirname(__file__),
-                                   "favicon.ico")
-            root.favicon_ico = tools.staticfile.handler(favicon)
-        
         return app
     
     def graft(self, wsgi_callable, script_name=""):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.