コード例 #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
ファイル: wsgi.py プロジェクト: axisofentropy/pulsar
 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
ファイル: wsgi.py プロジェクト: BazookaShao/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:
         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
ファイル: wsgi.py プロジェクト: axisofentropy/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)
コード例 #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
ファイル: test_wsgi.py プロジェクト: zzzz123321/pulsar
 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
ファイル: test_wsgi.py プロジェクト: zzzz123321/pulsar
    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
ファイル: wsgi.py プロジェクト: BazookaShao/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:
         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
ファイル: test_wsgi.py プロジェクト: zzzz123321/pulsar
 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
ファイル: wsgi.py プロジェクト: axisofentropy/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)
コード例 #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
ファイル: wsgi.py プロジェクト: Bhajju2510/SupervisedML
    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