From 941e410ee90e6f87cf35ce7a3d5da0aa90c447d6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 22 Apr 2015 00:04:53 +0200 Subject: Fix cgitb_catcher on Python 3 --- paste/cgitb_catcher.py | 4 ++++ tests/test_cgitb_catcher.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/paste/cgitb_catcher.py b/paste/cgitb_catcher.py index 3185506..f88ffb8 100644 --- a/paste/cgitb_catcher.py +++ b/paste/cgitb_catcher.py @@ -49,6 +49,8 @@ class CgitbMiddleware(object): [('content-type', 'text/html')], exc_info) response = self.exception_handler(exc_info, environ) + if six.PY3: + response = response.encode('utf8') return [response] def catching_iter(self, app_iter, environ): @@ -72,6 +74,8 @@ class CgitbMiddleware(object): response += ( '
Error in .close():
%s' % close_response) + if six.PY3: + response = response.encode('utf8') yield response def exception_handler(self, exc_info, environ): diff --git a/tests/test_cgitb_catcher.py b/tests/test_cgitb_catcher.py index c2c6632..a63f7d8 100644 --- a/tests/test_cgitb_catcher.py +++ b/tests/test_cgitb_catcher.py @@ -31,7 +31,7 @@ def after_start_response_app(environ, start_response): def iter_app(environ, start_response): start_response("200 OK", [('Content-type', 'text/plain')]) - return yielder(['this', ' is ', ' a', None]) + return yielder([b'this', b' is ', b' a', None]) def yielder(args): for arg in args: @@ -46,7 +46,10 @@ def yielder(args): def test_makes_exception(): res = do_request(bad_app) print(res) - assert 'bad_app() takes no arguments (2 given' in res + if six.PY3: + assert 'bad_app() takes 0 positional arguments but 2 were given' in res + else: + assert 'bad_app() takes no arguments (2 given' in res assert 'iterator = application(environ, start_response_wrapper)' in res assert 'lint.py' in res assert 'cgitb_catcher.py' in res -- cgit v1.2.1