Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #2745 -- Made the __repr__ methods for modpython and wsgi reque…

…st more

robust in the face of bad input, since they are needed for error handling.
Based on a patch from md@hudora.de.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3820 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f1c63992f77cd764239a09a6abe26a2781b34388 1 parent 5b490bb
Malcolm Tredinnick malcolmt authored
Showing with 38 additions and 4 deletions.
  1. +19 −2 django/core/handlers/modpython.py
  2. +19 −2 django/core/handlers/wsgi.py
21 django/core/handlers/modpython.py
View
@@ -16,9 +16,26 @@ def __init__(self, req):
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 '')
21 django/core/handlers/wsgi.py
View
@@ -78,9 +78,26 @@ def __init__(self, environ):
self.method = environ['REQUEST_METHOD'].upper()
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 '<WSGIRequest\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
- (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
- pformat(self.META))
+ (get, post, cookies, meta)
def get_full_path(self):
return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')
Please sign in to comment.
Something went wrong with that request. Please try again.