Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5595 -- Made `ModPythonRequest.__repr__` return a string inste…

…ad of a unicode object. Fixes the printout of the request object in those server error e-mails I never get :)

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7200 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d73c70d1ed34b53c21909f9d772a12bf85504601 1 parent 1e2852a
Gary Wilson Jr. authored March 08, 2008
7  django/core/handlers/modpython.py
@@ -6,7 +6,7 @@
6 6
 from django.core.handlers.base import BaseHandler
7 7
 from django.dispatch import dispatcher
8 8
 from django.utils import datastructures
9  
-from django.utils.encoding import force_unicode
  9
+from django.utils.encoding import force_unicode, smart_str
10 10
 
11 11
 # NOTE: do *not* import settings (or any module which eventually imports
12 12
 # settings) until after ModPythonHandler has been called; otherwise os.environ
@@ -36,8 +36,9 @@ def __repr__(self):
36 36
             meta = pformat(self.META)
37 37
         except:
38 38
             meta = '<could not parse>'
39  
-        return '<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
40  
-            (self.path, get, post, cookies, meta)
  39
+        return smart_str(u'<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' %
  40
+                         (self.path, unicode(get), unicode(post),
  41
+                          unicode(cookies), unicode(meta)))
41 42
 
42 43
     def get_full_path(self):
43 44
         return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
3  tests/regressiontests/requests/__init__.py
... ...
@@ -0,0 +1,3 @@
  1
+"""
  2
+Tests for Django's various Request objects.
  3
+"""
1  tests/regressiontests/requests/models.py
... ...
@@ -0,0 +1 @@
  1
+# Need a models module for the test runner.
34  tests/regressiontests/requests/tests.py
... ...
@@ -0,0 +1,34 @@
  1
+"""
  2
+>>> from django.http import HttpRequest
  3
+>>> print repr(HttpRequest())
  4
+<HttpRequest
  5
+GET:{},
  6
+POST:{},
  7
+COOKIES:{},
  8
+META:{}>
  9
+
  10
+>>> from django.core.handlers.wsgi import WSGIRequest
  11
+>>> print repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}))
  12
+<WSGIRequest
  13
+GET:<QueryDict: {}>,
  14
+POST:<QueryDict: {}>,
  15
+COOKIES:{},
  16
+META:{'REQUEST_METHOD': 'bogus', 'PATH_INFO': 'bogus'}>
  17
+
  18
+>>> from django.core.handlers.modpython import ModPythonRequest
  19
+>>> class FakeModPythonRequest(ModPythonRequest):
  20
+...    def __init__(self, *args, **kwargs):
  21
+...        super(FakeModPythonRequest, self).__init__(*args, **kwargs)
  22
+...        self._get = self._post = self._meta = self._cookies = {}
  23
+>>> class Dummy: pass
  24
+...
  25
+>>> req = Dummy()
  26
+>>> req.uri = 'bogus'
  27
+>>> print repr(FakeModPythonRequest(req))
  28
+<ModPythonRequest
  29
+path:bogus,
  30
+GET:{},
  31
+POST:{},
  32
+COOKIES:{},
  33
+META:{}>
  34
+"""

0 notes on commit d73c70d

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