summaryrefslogtreecommitdiff
path: root/paste/wsgiwrappers.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-21 16:01:04 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-21 16:01:04 +0200
commit5e7e91f896904d274f45570de60fe100fbaec0b7 (patch)
tree5e179a000b1ad119edd0d925d41ed470f78afcc9 /paste/wsgiwrappers.py
parentad47e4d46b3d6d5705243fbf68ad5ecc34108264 (diff)
downloadpaste-5e7e91f896904d274f45570de60fe100fbaec0b7.tar.gz
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
Diffstat (limited to 'paste/wsgiwrappers.py')
-rw-r--r--paste/wsgiwrappers.py5
1 files changed, 3 insertions, 2 deletions
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