mirror of
https://github.com/django/django.git
synced 2025-06-03 18:49:12 +00:00
Fixed #18561 -- Made HttpResponse.tell() support non-ascii chars
This commit is contained in:
parent
110c729309
commit
23f94f0741
@ -683,7 +683,7 @@ class HttpResponse(object):
|
|||||||
def tell(self):
|
def tell(self):
|
||||||
if self._base_content_is_iter:
|
if self._base_content_is_iter:
|
||||||
raise Exception("This %s instance cannot tell its position" % self.__class__)
|
raise Exception("This %s instance cannot tell its position" % self.__class__)
|
||||||
return sum([len(str(chunk)) for chunk in self._container])
|
return sum([len(chunk) for chunk in self])
|
||||||
|
|
||||||
class HttpResponseRedirect(HttpResponse):
|
class HttpResponseRedirect(HttpResponse):
|
||||||
status_code = 302
|
status_code = 302
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
@ -298,6 +299,17 @@ class HttpResponseTests(unittest.TestCase):
|
|||||||
self.assertRaises(UnicodeEncodeError,
|
self.assertRaises(UnicodeEncodeError,
|
||||||
getattr, r, 'content')
|
getattr, r, 'content')
|
||||||
|
|
||||||
|
def test_file_interface(self):
|
||||||
|
r = HttpResponse()
|
||||||
|
r.write(b"hello")
|
||||||
|
self.assertEqual(r.tell(), 5)
|
||||||
|
r.write("привет")
|
||||||
|
self.assertEqual(r.tell(), 17)
|
||||||
|
|
||||||
|
r = HttpResponse(['abc'])
|
||||||
|
self.assertRaises(Exception, r.write, 'def')
|
||||||
|
|
||||||
|
|
||||||
class CookieTests(unittest.TestCase):
|
class CookieTests(unittest.TestCase):
|
||||||
def test_encode(self):
|
def test_encode(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user