diff options
-rw-r--r-- | paste/wsgiwrappers.py | 4 | ||||
-rw-r--r-- | tests/test_wsgiwrappers.py | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/paste/wsgiwrappers.py b/paste/wsgiwrappers.py index 674054f..66bd896 100644 --- a/paste/wsgiwrappers.py +++ b/paste/wsgiwrappers.py @@ -360,11 +360,11 @@ class WSGIResponse(object): for c in self.cookies.values(): response_headers.append(('Set-Cookie', c.output(header=''))) start_response(status, response_headers) - is_file = isinstance(self.content, file) + is_file = hasattr(self.content, 'read') if 'wsgi.file_wrapper' in environ and is_file: return environ['wsgi.file_wrapper'](self.content) elif is_file: - return iter(lambda: self.content.read(), '') + return iter(lambda: self.content.read(), b'') return self.get_content() def determine_charset(self): diff --git a/tests/test_wsgiwrappers.py b/tests/test_wsgiwrappers.py index 75d03ed..43210c2 100644 --- a/tests/test_wsgiwrappers.py +++ b/tests/test_wsgiwrappers.py @@ -2,6 +2,7 @@ # (c) 2007 Philip Jenvey; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php import cgi +import io from paste.fixture import TestApp from paste.wsgiwrappers import WSGIRequest, WSGIResponse import six @@ -144,3 +145,19 @@ def test_wsgiresponse_charset(): assert isinstance(data, six.text_type) finally: WSGIResponse.defaults._pop_object() + +def test_call_wsgiresponse(): + resp = WSGIResponse(b'some content', 'application/octet-stream') + def sp(status, response_headers): + assert status == '200 OK' + assert sorted(response_headers) == [ + ('cache-control', 'no-cache'), + ('content-type', 'application/octet-stream'), + ] + assert resp({}, sp) == [b'some content'] + f = io.BytesIO(b'some content') + resp = WSGIResponse(f, 'application/octet-stream') + assert list(resp({}, sp)) == [b'some content'] + f = io.BytesIO() + resp = WSGIResponse(f, 'application/octet-stream') + assert resp({'wsgi.file_wrapper': lambda x: x}, sp) is f |