Comments (0)

Files changed (3)

File tests/test_response.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 import six
 import sys
 import zlib
-if sys.version >= '2.7':
+
+if six.PY3:
     from io import BytesIO as StringIO
 else:
     from cStringIO import StringIO
+    
 try:
     from hashlib import md5
 except ImportError:
     from gzip import GzipFile
     io = StringIO()
     gzip_f = GzipFile(filename='', mode='w', fileobj=io)
-    gzip_f.write('abc')
+    gzip_f.write(six.binary_type('abc', 'UTF-8'))
     gzip_f.close()
     body = io.getvalue()
     res = Response()

File webob/descriptors.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 import six
+import sys
 import warnings
 import re
 from datetime import datetime, date
         for k, v in r._headerlist:
             if k.lower() == key:
                 return v
-
+    
+    enc, esc = sys.getfilesystemencoding(), 'surrogateescape'
     def fset(r, value):
         fdel(r)
         if value is not None:
             if isinstance(value, six.text_type):
-                value = value.encode('ISO-8859-1') # standard encoding for headers
+                if six.PY3:
+                    # Convert an environment variable to a WSGI "bytes-as-unicode" string
+                    value = value.encode(enc, esc).decode('ISO-8859-1') 
+                else:
+                    # standard encoding for headers
+                    value = value.encode('ISO-8859-1') 
             r._headerlist.append((header, value))
 
     def fdel(r):

File webob/response.py Modified

View file
  • Ignore whitespace
  • Hide word diff
             raise TypeError(
                 "You cannot set Response.body to a unicode object (use "
                 "Response.unicode_body)")
-        if not isinstance(value, str):
+        if not isinstance(value, six.binary_type):
             raise TypeError(
                 "You can only set the body to a str (not %s)"
                 % type(value))