[py3k] http headers should be ascii-only unicode objects
authorRémi Cardona <remi.cardona@logilab.fr>
Mon, 12 Oct 2015 21:06:45 +0200
changeset 10733 9f66ac5eec1e
parent 10732 6231587fcfc5
child 10734 e64738c093e5
[py3k] http headers should be ascii-only unicode objects
web/request.py
--- a/web/request.py	Tue Oct 13 18:20:42 2015 +0200
+++ b/web/request.py	Mon Oct 12 21:06:45 2015 +0200
@@ -28,7 +28,7 @@
 from warnings import warn
 from io import BytesIO
 
-from six import PY2, text_type, string_types
+from six import PY2, binary_type, text_type, string_types
 from six.moves import http_client
 from six.moves.urllib.parse import urlsplit, quote as urlquote
 from six.moves.http_cookies import SimpleCookie
@@ -571,11 +571,11 @@
             header = [disposition]
             unicode_filename = None
             try:
-                ascii_filename = filename.encode('ascii')
+                ascii_filename = filename.encode('ascii').decode('ascii')
             except UnicodeEncodeError:
                 # fallback filename for very old browser
                 unicode_filename = filename
-                ascii_filename = filename.encode('ascii', 'ignore')
+                ascii_filename = filename.encode('ascii', 'ignore').decode('ascii')
             # escape " and \
             # see http://greenbytes.de/tech/tc2231/#attwithfilenameandextparamescaped
             ascii_filename = ascii_filename.replace('\x5c', r'\\').replace('"', r'\"')