diff options
Diffstat (limited to 'django/core/handlers/modpython.py')
| -rw-r--r-- | django/core/handlers/modpython.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py index 07c98e3b59..41d9a578c5 100644 --- a/django/core/handlers/modpython.py +++ b/django/core/handlers/modpython.py @@ -16,9 +16,26 @@ class ModPythonRequest(http.HttpRequest): self.path = req.uri def __repr__(self): + # Since this is called as part of error handling, we need to be very + # robust against potentially malformed input. + try: + get = pformat(self.GET) + except: + get = '<could not parse>' + try: + post = pformat(self.POST) + except: + post = '<could not parse>' + try: + cookies = pformat(self.COOKIES) + except: + cookies = '<could not parse>' + try: + meta = pformat(self.META) + except: + meta = '<could not parse>' return '<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \ - (self.path, pformat(self.GET), pformat(self.POST), pformat(self.COOKIES), - pformat(self.META)) + (self.path, get, post, cookies, meta) def get_full_path(self): return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '') @@ -155,8 +172,11 @@ def populate_apache_request(http_response, mod_python_req): for c in http_response.cookies.values(): mod_python_req.headers_out.add('Set-Cookie', c.output(header='')) mod_python_req.status = http_response.status_code - for chunk in http_response.iterator: - mod_python_req.write(chunk) + try: + for chunk in http_response: + mod_python_req.write(chunk) + finally: + http_response.close() def handler(req): # mod_python hooks into this function. |
