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).

  • Participants
  • Parent commits 8ca306c

Comments (0)

Files changed (1)

File 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=""):