示例#1
0
文件: green.py 项目: quantmind/lux
    def _call(self, pool, environ, start_response):
        if pool:
            wsgi_input = environ['wsgi.input']
            if wsgi_input and not isinstance(wsgi_input, GreenStream):
                environ['wsgi.input'] = GreenStream(wsgi_input)

        request = wsgi_request(environ)
        path = request.path
        try:
            self.app.on_request(data=request)
            hnd = self.router.resolve(path, request.method)
            if hnd:
                request.cache.set('app_handler', hnd.router)
                request.cache.set('urlargs', hnd.urlargs)
                response = self.wait(hnd.handler(request))
            else:
                raise Http404

        except Exception as exc:
            response = handle_wsgi_error(environ, exc)

        try:
            self.app.fire_event('on_response', data=(request, response))
        except Exception as exc:
            response = handle_wsgi_error(environ, exc)

        response.start(environ, start_response)
        return response
示例#2
0
 def test_handle_wsgi_error(self):
     handler = lambda request, exc: 'exception: %s' % exc
     environ = wsgi.test_wsgi_environ(extra={'error.handler': handler})
     try:
         raise ValueError('just a test')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'exception: just a test', ))
示例#3
0
文件: wsgi.py 项目: LoganTK/pulsar
 def test_handle_wsgi_error(self):
     environ = wsgi.test_wsgi_environ(
         extra={'error.handler': lambda request, failure: 'bla'})
     try:
         raise ValueError('just a test')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'bla',))
示例#4
0
文件: wsgi.py 项目: cyberj/pulsar
 def test_handle_wsgi_error(self):
     environ = {'wsgi_error_handler': lambda : 'bla'}
     try:
         raise ValueError('just a test')
     except:
         response = wsgi.handle_wsgi_error(environ, content_type='text/html')
     self.assertEqual(response.content_type, 'text/html')
     self.assertEqual(response.status_code, 500)
         
示例#5
0
 def test_handle_wsgi_error(self):
     handle500 = lambda request, exc: 'exception: %s' % exc
     environ = wsgi.test_wsgi_environ(
         extra={'error.handlers': {500: handle500}})
     try:
         raise ValueError('just a test')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'exception: just a test',))
示例#6
0
文件: wsgi.py 项目: LJS109/pulsar
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#7
0
 def test_handle_wsgi_error(self):
     environ = wsgi.test_wsgi_environ(extra=
                         {'error.handler': lambda request, failure: 'bla'})
     try:
         raise ValueError('just a test')
     except ValueError:
         failure = pulsar.Failure(sys.exc_info())
         failure.mute()
         response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'bla',))
示例#8
0
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#9
0
文件: wsgi.py 项目: luffyhwl/pulsar
    def test_handle_wsgi_error(self):
        def handler(request, exc):
            return "exception: %s" % exc

        environ = wsgi.test_wsgi_environ(extra={"error.handler": handler})
        try:
            raise ValueError("just a test")
        except ValueError as exc:
            response = wsgi.handle_wsgi_error(environ, exc)
        self.assertEqual(response.status_code, 500)
        self.assertEqual(response.content, (b"exception: just a test",))
示例#10
0
 async def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     request = await test_wsgi_request()
     request.environ['pulsar.cfg'] = cfg
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(request.environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, 'text/plain')
     self.assertEqual(len(response.content), 1)
示例#11
0
    async def test_handle_wsgi_error(self):

        def handler(request, exc):
            return 'exception: %s' % exc

        request = await test_wsgi_request()
        request.environ['error.handler'] = handler
        try:
            raise ValueError('just a test')
        except ValueError as exc:
            response = wsgi.handle_wsgi_error(request.environ, exc)
        self.assertEqual(response.status_code, 500)
        self.assertEqual(response.content, (b'exception: just a test',))
示例#12
0
 def test_handle_wsgi_error(self):
     environ = wsgi.test_wsgi_environ(
         extra={
             'error.handler': lambda request, failure: 'bla'
         })
     try:
         raise ValueError('just a test')
     except ValueError:
         failure = pulsar.Failure(sys.exc_info())
         failure.mute()
         response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'bla', ))
示例#13
0
文件: wsgi.py 项目: luffyhwl/pulsar
 def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set("debug", True)
     headers = [("Accept", "*/*")]
     environ = wsgi.test_wsgi_environ(extra={"pulsar.cfg": cfg}, headers=headers)
     try:
         raise ValueError("just a test for debug wsgi error handler")
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, "text/html")
     self.assertTrue(html.startswith(b"<!DOCTYPE html>"))
     self.assertTrue(b"<title>500 Internal Server Error</title>" in html)
示例#14
0
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError:
         exc_info = sys.exc_info()
     failure = pulsar.Failure(exc_info)
     failure.mute()
     response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#15
0
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError:
         exc_info = sys.exc_info()
     failure = pulsar.Failure(exc_info)
     failure.mute()
     response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#16
0
文件: wsgi.py 项目: LJS109/pulsar
 def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     headers = [('Accept', '*/*')]
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg},
                                      headers=headers)
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, 'text/html')
     self.assertTrue(html.startswith(b'<!DOCTYPE html>'))
     self.assertTrue(b'<title>500 Internal Server Error</title>' in html)
示例#17
0
 async def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     request = await test_wsgi_request()
     request.environ['pulsar.cfg'] = cfg
     request.environ['default.content_type'] = 'text/html'
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(request.environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, 'text/html')
     self.assertTrue(html.startswith(b'<!DOCTYPE html>'))
     self.assertTrue(b'<title>500 Internal Server Error</title>' in html)
示例#18
0
 def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     headers = [('Accept', '*/*')]
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg},
                                      headers=headers)
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, 'text/html')
     self.assertTrue(html.startswith(b'<!DOCTYPE html>'))
     self.assertTrue(b'<title>500 Internal Server Error</title>' in html)
示例#19
0
    def _call(self, environ, start_response):
        if environ['wsgi.input']:
            environ['wsgi.input'] = GreenStream(environ['wsgi.input'])
        response = None
        try:
            for middleware in self.middleware:
                response = wait(middleware(environ, start_response))
                if response is not None:
                    break
            if response is None:
                raise Http404

        except Exception as exc:
            response = wait(handle_wsgi_error(environ, exc))

        if isinstance(response, WsgiResponse) and not response.started:
            for middleware in self.response_middleware:
                response = wait(middleware(environ, response)) or response
            response.start(start_response)
        return response
示例#20
0
文件: wsgi.py 项目: kwsy/pulsar
    def _call(self, environ, start_response):
        if environ['wsgi.input']:
            environ['wsgi.input'] = GreenStream(environ['wsgi.input'])
        response = None
        try:
            for middleware in self.middleware:
                response = wait(middleware(environ, start_response))
                if response is not None:
                    break
            if response is None:
                raise Http404

        except Exception as exc:
            response = wait(handle_wsgi_error(environ, exc))

        if isinstance(response, WsgiResponse) and not response.started:
            for middleware in self.response_middleware:
                response = wait(middleware(environ, response)) or response
            response.start(start_response)
        return response
示例#21
0
    def _call(self, environ, start_response):
        wsgi_input = environ['wsgi.input']
        if wsgi_input and not isinstance(wsgi_input, GreenStream):
            environ['wsgi.input'] = GreenStream(wsgi_input)
        response = None
        try:
            for middleware in self.middleware:
                response = wait(middleware(environ, start_response))
                if response is not None:
                    break
            if response is None:
                raise Http404

        except Exception as exc:
            response = wait(handle_wsgi_error(environ, exc))

        if not getattr(response, '__wsgi_started__', True):
            for middleware in self.response_middleware:
                response = wait(middleware(environ, response)) or response
            response.start(environ, start_response)
        return response
示例#22
0
文件: wsgi.py 项目: quantmind/pulsar
    def _call(self, environ, start_response):
        wsgi_input = environ['wsgi.input']
        if wsgi_input and not isinstance(wsgi_input, GreenStream):
            environ['wsgi.input'] = GreenStream(wsgi_input)
        response = None
        try:
            for middleware in self.middleware:
                response = wait(middleware(environ, start_response))
                if response is not None:
                    break
            if response is None:
                raise Http404

        except Exception as exc:
            response = wait(handle_wsgi_error(environ, exc))

        if not getattr(response, '__wsgi_started__', True):
            for middleware in self.response_middleware:
                response = wait(middleware(environ, response)) or response
            response.start(environ, start_response)
        return response