Example #1
0
File: wsgi.py Project: syfun/pweby
class MainHandler(object):
    """

    """
    def __init__(self, *apps):
        self.mapper = Mapper()
        self.apps = {}
        for app in apps:
            self.add_app(app)

    @dec.wsgify
    def __call__(self, req):
        result = self.mapper.match(req.path)
        if not result:
            return exc.HTTPNotFound()
        app_name, func_name = result.pop('controller').split('&&&')
        app = self.apps[app_name]
        req.environ['_func_name'] = func_name
        req.environ['_kwargs'] = result
        return req.get_response(app)

    def add_app(self, app):
        """

        :param app:
        :return:
        """
        if not is_app(app):
            raise exception.InvalidApplication(app=app.__name__)
        _app = app(self)
        self.apps[str(_app)] = _app
Example #2
0
File: wsgi.py Project: syfun/pweby
 def __init__(self, *apps):
     self.mapper = Mapper()
     self.apps = {}
     for app in apps:
         self.add_app(app)