summaryrefslogtreecommitdiff
path: root/django/http
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-17 07:11:37 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-17 07:11:37 +0000
commitbccb8897e6ab0fe8d2e5b9bcb725ac28b1c8e566 (patch)
treed3abbbdf27fa5ae3c78a9dc510798cd521e46684 /django/http
parent44dd91ec6d39525e52b78f7fff6de8531b980f5f (diff)
Fixed #4565 -- Changed template rendering to use iterators, rather than
creating large strings, as much as possible. This is all backwards compatible. Thanks, Brian Harring. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5482 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/http')
-rw-r--r--django/http/__init__.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index ca3b5eab24..a8c8afe433 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -222,6 +222,12 @@ class HttpResponse(object):
content = ''.join(self._container)
if isinstance(content, unicode):
content = content.encode(self._charset)
+
+ # If self._container was an iterator, we have just exhausted it, so we
+ # need to save the results for anything else that needs access
+ if not self._is_string:
+ self._container = [content]
+ self._is_string = True
return content
def _set_content(self, value):
@@ -231,14 +237,10 @@ class HttpResponse(object):
content = property(_get_content, _set_content)
def __iter__(self):
- self._iterator = self._container.__iter__()
- return self
-
- def next(self):
- chunk = self._iterator.next()
- if isinstance(chunk, unicode):
- chunk = chunk.encode(self._charset)
- return chunk
+ for chunk in self._container:
+ if isinstance(chunk, unicode):
+ chunk = chunk.encode(self._charset)
+ yield chunk
def close(self):
if hasattr(self._container, 'close'):