=== modified file 'django/core/handlers/wsgi.py'
|
|
|
174 | 174 | REQUEST = property(_get_request) |
175 | 175 | raw_post_data = property(_get_raw_post_data) |
176 | 176 | |
| 177 | class IterConsumedSignal(object): |
| 178 | |
| 179 | def __iter__(self): |
| 180 | return self |
| 181 | |
| 182 | def next(self): |
| 183 | dispatcher.send(signal=signals.request_finished) |
| 184 | raise StopIteration() |
| 185 | IterConsumedSignal = IterConsumedSignal() |
| 186 | |
| 187 | class ResponseWrapper(object): |
| 188 | |
| 189 | def __init__(self, response): |
| 190 | self._response = response |
| 191 | if hasattr(self._response, 'close'): |
| 192 | self.close = self._response.close |
| 193 | |
| 194 | def __iter__(self): |
| 195 | assert self._response is not None |
| 196 | try: |
| 197 | if isinstance(self._response, basestring): |
| 198 | return chain([self._response], IterConsumedSignal) |
| 199 | return chain(self._response, IterConsumedSignal) |
| 200 | finally: |
| 201 | self._response = None |
| 202 | |
| 203 | |
177 | 204 | class WSGIHandler(BaseHandler): |
178 | 205 | def __call__(self, environ, start_response): |
179 | 206 | from django.conf import settings |
… |
… |
|
192 | 219 | for middleware_method in self._response_middleware: |
193 | 220 | response = middleware_method(request, response) |
194 | 221 | |
195 | | finally: |
| 222 | except: |
196 | 223 | dispatcher.send(signal=signals.request_finished) |
| 224 | raise |
197 | 225 | |
198 | 226 | try: |
199 | 227 | status_text = STATUS_CODE_TEXT[response.status_code] |
… |
… |
|
204 | 232 | for c in response.cookies.values(): |
205 | 233 | response_headers.append(('Set-Cookie', c.output(header=''))) |
206 | 234 | start_response(status, response_headers) |
207 | | return response |
| 235 | return ResponseWrapper(response) |