mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	| @@ -85,7 +85,7 @@ from django.core.files import uploadhandler | |||||||
| from django.http.multipartparser import MultiPartParser | from django.http.multipartparser import MultiPartParser | ||||||
| from django.http.utils import * | from django.http.utils import * | ||||||
| from django.utils.datastructures import MultiValueDict, ImmutableList | from django.utils.datastructures import MultiValueDict, ImmutableList | ||||||
| from django.utils.encoding import smart_bytes, smart_str, iri_to_uri, force_text | from django.utils.encoding import force_bytes, force_text, iri_to_uri, smart_bytes, smart_str | ||||||
| from django.utils.http import cookie_date | from django.utils.http import cookie_date | ||||||
| from django.utils import six | from django.utils import six | ||||||
| from django.utils import timezone | from django.utils import timezone | ||||||
| @@ -670,10 +670,12 @@ class HttpResponse(object): | |||||||
|                         expires='Thu, 01-Jan-1970 00:00:00 GMT') |                         expires='Thu, 01-Jan-1970 00:00:00 GMT') | ||||||
|  |  | ||||||
|     def _get_content(self): |     def _get_content(self): | ||||||
|         if self.has_header('Content-Encoding'): |         # The logic below obeys the following constraints: | ||||||
|             # XXX this doesn't work under Python 3 when e is an integer (#18764) |         # - do not perform any encoding if a Content-Encoding is set (#4969) | ||||||
|             return b''.join([bytes(e) for e in self._container]) |         # - force string conversion of non-string types (#16494) | ||||||
|         return b''.join([smart_bytes(e, self._charset) for e in self._container]) |         # - avoid simply calling bytes() with Python 3 (#18764) | ||||||
|  |         encoding = 'ascii' if self.has_header('Content-Encoding') else self._charset | ||||||
|  |         return b''.join(force_bytes(e, encoding) for e in self._container) | ||||||
|  |  | ||||||
|     def _set_content(self, value): |     def _set_content(self, value): | ||||||
|         if hasattr(value, '__iter__') and not isinstance(value, (bytes, six.string_types)): |         if hasattr(value, '__iter__') and not isinstance(value, (bytes, six.string_types)): | ||||||
| @@ -690,10 +692,9 @@ class HttpResponse(object): | |||||||
|         return self |         return self | ||||||
|  |  | ||||||
|     def __next__(self): |     def __next__(self): | ||||||
|         chunk = next(self._iterator) |         # Use the same logic as _get_content. | ||||||
|         if isinstance(chunk, six.text_type): |         encoding = 'ascii' if self.has_header('Content-Encoding') else self._charset | ||||||
|             chunk = chunk.encode(self._charset) |         return force_bytes(next(self._iterator), encoding) | ||||||
|         return bytes(chunk) |  | ||||||
|  |  | ||||||
|     next = __next__             # Python 2 compatibility |     next = __next__             # Python 2 compatibility | ||||||
|  |  | ||||||
|   | |||||||
| @@ -296,7 +296,7 @@ class HttpResponseTests(unittest.TestCase): | |||||||
|         my_iter = r.__iter__() |         my_iter = r.__iter__() | ||||||
|         result = list(my_iter) |         result = list(my_iter) | ||||||
|         #'\xde\x9e' == unichr(1950).encode('utf-8') |         #'\xde\x9e' == unichr(1950).encode('utf-8') | ||||||
|         self.assertEqual(result, ['1', '2', '3', b'\xde\x9e']) |         self.assertEqual(result, [b'1', b'2', b'3', b'\xde\x9e']) | ||||||
|         self.assertEqual(r.content, b'123\xde\x9e') |         self.assertEqual(r.content, b'123\xde\x9e') | ||||||
|  |  | ||||||
|         #with Content-Encoding header |         #with Content-Encoding header | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user