Ticket #2560: 2560.1.patch
File 2560.1.patch, 3.8 KB (added by , 18 years ago) |
---|
-
django/http/__init__.py
161 161 if not mimetype: 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} 170 170 self.cookies = SimpleCookie() … … 213 213 self.cookies[key]['max-age'] = 0 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) 219 219 return content 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 227 def __iter__(self): 228 self._iterator = self._container.__iter__() 229 return self 233 230 234 iterator = property(_get_iterator) 231 def next(self): 232 chunk = self._iterator.next() 233 if isinstance(chunk, unicode): 234 chunk = chunk.encode(self._charset) 235 return chunk 235 236 237 def close(self): 238 if hasattr(self._container, 'close'): 239 self._container.close() 240 236 241 # The remaining methods partially implement the file-like object interface. 237 242 # See http://docs.python.org/lib/bltin-file-objects.html 238 243 def write(self, content): 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): 244 249 pass … … 246 251 def tell(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): 252 257 def __init__(self, redirect_to): -
django/core/handlers/wsgi.py
163 163 for c in response.cookies.values(): 164 164 response_headers.append(('Set-Cookie', c.output(header=''))) 165 165 start_response(status, response_headers) 166 return response .iterator166 return response # response is a WSGI-compilant iterator -
django/core/handlers/modpython.py
155 155 for c in http_response.cookies.values(): 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): 162 165 # mod_python hooks into this function.