From 5e7e91f896904d274f45570de60fe100fbaec0b7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 21 Apr 2015 16:01:04 +0200 Subject: Fix WSGIResponse on Python 3 HTTP body must be bytes. Don't check if __iter__() method to check if content is a list or tuple, because bytes and str now have this method on Python 3. Instead, check explicitly for bytes and str types using the six module. Port wsgiwrappers test to Python 3, fix bytes/unicode issues: * HTTP body must be bytes * Filenames are native strings, request ensures that filenames are unicode --- paste/wsgiwrappers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'paste/wsgiwrappers.py') diff --git a/paste/wsgiwrappers.py b/paste/wsgiwrappers.py index 290179d..1cbae4f 100644 --- a/paste/wsgiwrappers.py +++ b/paste/wsgiwrappers.py @@ -14,6 +14,7 @@ try: except ImportError: # Python 2 from Cookie import SimpleCookie +import six from paste.request import EnvironHeaders, get_cookie_dict, \ parse_dict_querystring, parse_formvars @@ -303,7 +304,7 @@ class WSGIResponse(object): default=dict(content_type='text/html', charset='utf-8', errors='strict', headers={'Cache-Control':'no-cache'}) ) - def __init__(self, content='', mimetype=None, code=200): + def __init__(self, content=b'', mimetype=None, code=200): self._iter = None self._is_str_iter = True @@ -409,7 +410,7 @@ class WSGIResponse(object): self.cookies[key]['max-age'] = 0 def _set_content(self, content): - if hasattr(content, '__iter__'): + if not isinstance(content, (six.binary_type, six.text_type)): self._iter = content if isinstance(content, list): self._is_str_iter = True -- cgit v1.2.1