From bf4da7a4420ccacf76090301a1e0efa1eea17751 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 3 Aug 2012 23:01:47 +0200 Subject: [PATCH] [py3] Made a small fix in django.http. This is necessary for the 'utils' tests to pass. --- django/http/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/django/http/__init__.py b/django/http/__init__.py index b23304f346..d559fdf7c6 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -549,7 +549,12 @@ class HttpResponse(object): for value in values: if isinstance(value, six.text_type): try: - value = value.encode('us-ascii') + if not six.PY3: + value = value.encode('us-ascii') + else: + # In Python 3, use a string in headers, + # but ensure in only contains ASCII characters. + value.encode('us-ascii') except UnicodeError as e: e.reason += ', HTTP response headers must be in US-ASCII format' raise