Ticket #13222: 13222.patch

File 13222.patch, 1.5 KB (added by Aymeric Augustin, 12 years ago)
  • django/http/response.py

    diff --git a/django/http/response.py b/django/http/response.py
    index 4a5c479..49145cd 100644
    a b class HttpResponse(HttpResponseBase):  
    260260        else:
    261261            self._container = [value]
    262262            self._base_content_is_iter = False
     263        self._iterator = iter(self._container)
    263264
    264265    def __iter__(self):
    265         self._iterator = iter(self._container)
    266266        return self
    267267
    268268    def __next__(self):
    class HttpResponse(HttpResponseBase):  
    284284    def tell(self):
    285285        if self._base_content_is_iter:
    286286            raise Exception("This %s instance cannot tell its position" % self.__class__.__name__)
    287         return sum([len(chunk) for chunk in self])
     287        return len(self.content)
    288288
    289289
    290290class StreamingHttpResponse(HttpResponseBase):
  • tests/regressiontests/httpwrappers/tests.py

    diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
    index bfb4ae1..803cbf0 100644
    a b class HttpResponseTests(unittest.TestCase):  
    330330        self.assertRaises(UnicodeEncodeError,
    331331                          getattr, r, 'content')
    332332
     333    def test_iterator_isnt_rewound(self):
     334        # Regression test for #13222
     335        r = HttpResponse('abc')
     336        i = iter(r)
     337        self.assertEqual(list(i), [b'abc'])
     338        self.assertEqual(list(i), [])
     339
    333340    def test_file_interface(self):
    334341        r = HttpResponse()
    335342        r.write(b"hello")
Back to Top