Changeset 3791
- Timestamp:
- 09/22/06 07:32:00 (2 years ago)
- Files:
-
- django/trunk/django/core/handlers/modpython.py (modified) (1 diff)
- django/trunk/django/core/handlers/wsgi.py (modified) (1 diff)
- django/trunk/django/http/__init__.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/handlers/modpython.py
r3414 r3791 156 156 mod_python_req.headers_out.add('Set-Cookie', c.output(header='')) 157 157 mod_python_req.status = http_response.status_code 158 for chunk in http_response.iterator: 159 mod_python_req.write(chunk) 158 try: 159 for chunk in http_response: 160 mod_python_req.write(chunk) 161 finally: 162 http_response.close() 160 163 161 164 def handler(req): django/trunk/django/core/handlers/wsgi.py
r3411 r3791 164 164 response_headers.append(('Set-Cookie', c.output(header=''))) 165 165 start_response(status, response_headers) 166 return response .iterator166 return response django/trunk/django/http/__init__.py
r3545 r3791 162 162 mimetype = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, settings.DEFAULT_CHARSET) 163 163 if hasattr(content, '__iter__'): 164 self._ iterator = content164 self._container = content 165 165 self._is_string = False 166 166 else: 167 self._ iterator = [content]167 self._container = [content] 168 168 self._is_string = True 169 169 self.headers = {'Content-Type': mimetype} … … 214 214 215 215 def _get_content(self): 216 content = ''.join(self._ iterator)216 content = ''.join(self._container) 217 217 if isinstance(content, unicode): 218 218 content = content.encode(self._charset) … … 220 220 221 221 def _set_content(self, value): 222 self._ iterator = [value]222 self._container = [value] 223 223 self._is_string = True 224 224 225 225 content = property(_get_content, _set_content) 226 226 227 def _get_iterator(self): 228 "Output iterator. Converts data into client charset if necessary." 229 for chunk in self._iterator: 230 if isinstance(chunk, unicode): 231 chunk = chunk.encode(self._charset) 232 yield chunk 233 234 iterator = property(_get_iterator) 227 def __iter__(self): 228 self._iterator = self._container.__iter__() 229 return self 230 231 def next(self): 232 chunk = self._iterator.next() 233 if isinstance(chunk, unicode): 234 chunk = chunk.encode(self._charset) 235 return chunk 236 237 def close(self): 238 if hasattr(self._container, 'close'): 239 self._container.close() 235 240 236 241 # The remaining methods partially implement the file-like object interface. … … 239 244 if not self._is_string: 240 245 raise Exception, "This %s instance is not writable" % self.__class__ 241 self._ iterator.append(content)246 self._container.append(content) 242 247 243 248 def flush(self): … … 247 252 if not self._is_string: 248 253 raise Exception, "This %s instance cannot tell its position" % self.__class__ 249 return sum([len(chunk) for chunk in self._ iterator])254 return sum([len(chunk) for chunk in self._container]) 250 255 251 256 class HttpResponseRedirect(HttpResponse):
