# This file is part of Moksha.
# 
# Moksha is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# Moksha is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Moksha.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2008, Red Hat, Inc.
# Authors: Luke Macken <lmacken@redhat.com>

from pylons.wsgiapp import PylonsApp

class MokshaAppDispatcher(PylonsApp):
    """ Moksha WSGI Application Dispatcher.

    This class handles resolving and dispatching to moksha applications.
    It is instantiated and utilized by the 
    :class:`moksha.middleware.MokshaMiddleware`.
    """
    root = None

    def resolve(self, environ, start_response): 
        """ Uses dispatching information found in
        ``environ['wsgiorg.routing_args']`` to retrieve the application
        name and return the controller instance from the appropriate
        moksha application.

        """
        environ['pylons.routes_dict'] = environ['wsgiorg.routing_args'][1]
        if not self.root:
            from moksha.controllers.root import RootController
            self.root = RootController()
        return self.root

@@ -1036,16 +1036,189 @@
 = None%0A%0A
+    def __init__(self):%0A        super(MokshaAppDispatcher, self).__init__()%0A        from moksha.controllers.root import RootController%0A        self.root = RootController()%0A%0A
     def 
@@ -1569,138 +1569,8 @@
 %5B1%5D%0A
-        if not self.root:%0A            from moksha.controllers.root import RootController%0A            self.root = RootController()%0A
     

Create Moksha's RootController in the MokshaAppDispatcher.__init__