Ticket #13222: httpresponse2.diff

File httpresponse2.diff, 1.7 KB (added by teepark, 14 years ago)

same patch but tests moved from doctest to unittest

  • django/http/__init__.py

     
    600600    content = property(_get_content, _set_content)
    601601
    602602    def __iter__(self):
    603         self._iterator = iter(self._container)
    604         return self
     603        for chunk in self._container:
     604            if isinstance(chunk, unicode):
     605                chunk = chunk.encode(self._charset)
     606            yield str(chunk)
    605607
    606     def next(self):
    607         chunk = self._iterator.next()
    608         if isinstance(chunk, unicode):
    609             chunk = chunk.encode(self._charset)
    610         return str(chunk)
    611 
    612608    def close(self):
    613609        if hasattr(self._container, 'close'):
    614610            self._container.close()
  • tests/regressiontests/httpwrappers/tests.py

     
    243243        self.assertRaises(BadHeaderError, r.__setitem__, 'test\rstr', 'test')
    244244        self.assertRaises(BadHeaderError, r.__setitem__, 'test\nstr', 'test')
    245245
     246    def test_iteration(self):
     247        r = HttpResponse("foobar")
     248        it = iter(r)
     249        self.assertEqual(list(it), ["foobar"])
     250        self.assertEqual(list(it), [])
     251
     252        r = HttpResponse(["foo", "bar", "spam", "eggs"])
     253        it1 = iter(r)
     254        it2 = iter(r)
     255        self.assertEqual(zip(it1, it2), [("foo", "foo"), ("bar", "bar"),
     256            ("spam", "spam"), ("eggs", "eggs")])
     257
    246258class CookieTests(unittest.TestCase):
    247259    def test_encode(self):
    248260        """
Back to Top