Ticket #13222: httpresponse.diff

File httpresponse.diff, 1.3 KB (added by teepark, 14 years ago)

just makes HttpResponse.__iter__ a generator, and adds a regression test

  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 683212f..3a067c0 100644
    a b class HttpResponse(object):  
    371371    content = property(_get_content, _set_content)
    372372
    373373    def __iter__(self):
    374         self._iterator = iter(self._container)
    375         return self
    376 
    377     def next(self):
    378         chunk = self._iterator.next()
    379         if isinstance(chunk, unicode):
    380             chunk = chunk.encode(self._charset)
    381         return str(chunk)
     374        for chunk in self._container:
     375            if isinstance(chunk, unicode):
     376                chunk = chunk.encode(self._charset)
     377            yield str(chunk)
    382378
    383379    def close(self):
    384380        if hasattr(self._container, 'close'):
  • tests/regressiontests/httpwrappers/tests.py

    diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
    index 04099be..99727bf 100644
    a b BadHeaderError: Header values can't contain newlines (got 'test\\nstr')  
    463463>>> x.update(y)
    464464>>> x.getlist('a')
    465465[u'1', u'2', u'3', u'4']
     466
     467#
     468# Regression test for #13222: HttpResponse iteration
     469#
     470>>> it = iter(HttpResponse("foobar"))
     471>>> list(it), list(it)
     472(['foobar'], [])
    466473"""
    467474
    468475from django.http import QueryDict, HttpResponse
Back to Top