summaryrefslogtreecommitdiff
path: root/django/core/handlers/modpython.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/core/handlers/modpython.py')
-rw-r--r--django/core/handlers/modpython.py54
1 files changed, 34 insertions, 20 deletions
diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py
index 07c98e3b59..5fc41a048b 100644
--- a/django/core/handlers/modpython.py
+++ b/django/core/handlers/modpython.py
@@ -16,14 +16,32 @@ 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 '')
def is_secure(self):
+ # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions
return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on'
def _load_post_and_files(self):
@@ -122,10 +140,6 @@ class ModPythonHandler(BaseHandler):
# that use settings now can work
from django.conf import settings
- if settings.ENABLE_PSYCO:
- import psyco
- psyco.profile()
-
# if we need to set up middleware, now that settings works we can do it now.
if self._request_middleware is None:
self.load_middleware()
@@ -133,7 +147,7 @@ class ModPythonHandler(BaseHandler):
dispatcher.send(signal=signals.request_started)
try:
request = ModPythonRequest(req)
- response = self.get_response(req.uri, request)
+ response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
@@ -143,20 +157,20 @@ class ModPythonHandler(BaseHandler):
dispatcher.send(signal=signals.request_finished)
# Convert our custom HttpResponse object back into the mod_python req.
- populate_apache_request(response, req)
- return 0 # mod_python.apache.OK
+ req.content_type = response['Content-Type']
+ for key, value in response.headers.items():
+ if key != 'Content-Type':
+ req.headers_out[key] = value
+ for c in response.cookies.values():
+ req.headers_out.add('Set-Cookie', c.output(header=''))
+ req.status = response.status_code
+ try:
+ for chunk in response:
+ req.write(chunk)
+ finally:
+ response.close()
-def populate_apache_request(http_response, mod_python_req):
- "Populates the mod_python request object with an HttpResponse"
- mod_python_req.content_type = http_response['Content-Type']
- for key, value in http_response.headers.items():
- if key != 'Content-Type':
- mod_python_req.headers_out[key] = value
- 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)
+ return 0 # mod_python.apache.OK
def handler(req):
# mod_python hooks into this function.