Ticket #18561: 18561.diff

File 18561.diff, 1.4 KB (added by Claude Paroz, 12 years ago)

Make tell() handle unicode content

  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 51e6ca2..8f97428 100644
    a b class HttpResponse(object):  
    694694    def tell(self):
    695695        if self._base_content_is_iter:
    696696            raise Exception("This %s instance cannot tell its position" % self.__class__)
    697         return sum([len(str(chunk)) for chunk in self._container])
     697        return sum([len(chunk) for chunk in self])
    698698
    699699class HttpResponseRedirect(HttpResponse):
    700700    status_code = 302
  • tests/regressiontests/httpwrappers/tests.py

    diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
    index 870324b..d52adc4 100644
    a b  
     1# -*- encoding: utf-8 -*-
    12from __future__ import unicode_literals
    23
    34import copy
    class HttpResponseTests(unittest.TestCase):  
    298299        self.assertRaises(UnicodeEncodeError,
    299300                          getattr, r, 'content')
    300301
     302    def test_file_interface(self):
     303        r = HttpResponse()
     304        r.write(b"hello")
     305        self.assertEqual(r.tell(), 5)
     306        r.write("привет")
     307        self.assertEqual(r.tell(), 17)
     308
     309        r = HttpResponse(['abc'])
     310        self.assertRaises(Exception, r.write, 'def')
     311
     312
    301313class CookieTests(unittest.TestCase):
    302314    def test_encode(self):
    303315        """
Back to Top