Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored September 25, 2006
21  django/core/handlers/modpython.py
@@ -16,9 +16,26 @@ def __init__(self, req):
16 16
         self.path = req.uri
17 17
 
18 18
     def __repr__(self):
  19
+        # Since this is called as part of error handling, we need to be very
  20
+        # robust against potentially malformed input.
  21
+        try:
  22
+            get = pformat(self.GET)
  23
+        except:
  24
+            get = '<could not parse>'
  25
+        try:
  26
+            post = pformat(self.POST)
  27
+        except:
  28
+            post = '<could not parse>'
  29
+        try:
  30
+            cookies = pformat(self.COOKIES)
  31
+        except:
  32
+            cookies = '<could not parse>'
  33
+        try:
  34
+            meta = pformat(self.META)
  35
+        except:
  36
+            meta = '<could not parse>'
19 37
         return '<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
20  
-            (self.path, pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
21  
-            pformat(self.META))
  38
+            (self.path, get, post, cookies, meta)
22 39
 
23 40
     def get_full_path(self):
24 41
         return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
21  django/core/handlers/wsgi.py
@@ -78,9 +78,26 @@ def __init__(self, environ):
78 78
         self.method = environ['REQUEST_METHOD'].upper()
79 79
 
80 80
     def __repr__(self):
  81
+        # Since this is called as part of error handling, we need to be very
  82
+        # robust against potentially malformed input.
  83
+        try:
  84
+            get = pformat(self.GET)
  85
+        except:
  86
+            get = '<could not parse>'
  87
+        try:
  88
+            post = pformat(self.POST)
  89
+        except:
  90
+            post = '<could not parse>'
  91
+        try:
  92
+            cookies = pformat(self.COOKIES)
  93
+        except:
  94
+            cookies = '<could not parse>'
  95
+        try:
  96
+            meta = pformat(self.META)
  97
+        except:
  98
+            meta = '<could not parse>'
81 99
         return '<WSGIRequest\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
82  
-            (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
83  
-            pformat(self.META))
  100
+            (get, post, cookies, meta)
84 101
 
85 102
     def get_full_path(self):
86 103
         return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')

0 notes on commit f1c6399

Please sign in to comment.
Something went wrong with that request. Please try again.