示例#1
0
文件: webapp.py 项目: lafada/kalapy
    def dispatch(self, environ, start_response):
        """The actual wsgi application. This is not implemented in `__call__`
        so that wsgi middlewares can be applied without losing a reference to
        the class.
        """
        _local.current_app = self
        _local.request = request = Request(environ)
        request.url_adapter = adapter = self.urls.bind_to_environ(environ)

        signals.send('request-started')
        try:
            response = self.get_response(request)
        except HTTPException, e:
            response = e
示例#2
0
文件: signals.py 项目: lafada/kalapy
    def test_disconnect(self):

        @signals.connect('foo-signal')
        def foo_handler1(bar):
            return bar

        @signals.connect('foo-signal')
        def foo_handler2(bar):
            return bar

        @signals.connect('foo-signal')
        def foo_handler3(bar):
            return bar

        assert signals.send('foo-signal', bar='BAR') == ['BAR', 'BAR', 'BAR']
        signals.disconnect('foo-signal')
        assert signals.send('foo-signal', bar='FOO') == []
示例#3
0
文件: signals.py 项目: lafada/kalapy
    def test_connect(self):

        @signals.connect('foo-signal')
        def foo_handler1(bar):
            return 1, bar

        @signals.connect('foo-signal')
        def foo_handler2(bar):
            return 2, bar

        @signals.connect('foo-signal')
        def foo_handler3(bar):
            return 3, bar

        assert signals.send('foo-signal', bar='BAR') == [(1, 'BAR'), (2, 'BAR'), (3, 'BAR')]
示例#4
0
文件: webapp.py 项目: lafada/kalapy
    def dispatch(self, environ, start_response):
        """The actual wsgi application. This is not implemented in `__call__`
        so that wsgi middlewares can be applied without losing a reference to
        the class.
        """
        _local.current_app = self
        _local.request = request = Request(environ)
        request.url_adapter = adapter = self.urls.bind_to_environ(environ)

        signals.send('request-started')
        try:
            response = self.get_response(request)
        except HTTPException, e:
            response = e
        except Exception, e:
            signals.send('request-exception', error=e)
            raise
        finally:
            signals.send('request-finished')

        response = self.process_response(request, response)

        return ClosingIterator(response(environ, start_response),
                [_local_manager.cleanup])

    def __call__(self, environ, start_response):
        return self.dispatch(environ, start_response)


def route(rule, **options):
    """A decorator to register a view function for a given URL rule.