Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@gdub gdub authored
View
7 django/core/handlers/modpython.py
@@ -6,7 +6,7 @@
from django.core.handlers.base import BaseHandler
from django.dispatch import dispatcher
from django.utils import datastructures
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_unicode, smart_str
# NOTE: do *not* import settings (or any module which eventually imports
# settings) until after ModPythonHandler has been called; otherwise os.environ
@@ -36,8 +36,9 @@ def __repr__(self):
meta = pformat(self.META)
except:
meta = '<could not parse>'
- return '<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
- (self.path, get, post, cookies, meta)
+ return smart_str(u'<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' %
+ (self.path, unicode(get), unicode(post),
+ unicode(cookies), unicode(meta)))
def get_full_path(self):
return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
View
3  tests/regressiontests/requests/__init__.py
@@ -0,0 +1,3 @@
+"""
+Tests for Django's various Request objects.
+"""
View
1  tests/regressiontests/requests/models.py
@@ -0,0 +1 @@
+# Need a models module for the test runner.
View
34 tests/regressiontests/requests/tests.py
@@ -0,0 +1,34 @@
+"""
+>>> from django.http import HttpRequest
+>>> print repr(HttpRequest())
+<HttpRequest
+GET:{},
+POST:{},
+COOKIES:{},
+META:{}>
+
+>>> from django.core.handlers.wsgi import WSGIRequest
+>>> print repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}))
+<WSGIRequest
+GET:<QueryDict: {}>,
+POST:<QueryDict: {}>,
+COOKIES:{},
+META:{'REQUEST_METHOD': 'bogus', 'PATH_INFO': 'bogus'}>
+
+>>> from django.core.handlers.modpython import ModPythonRequest
+>>> class FakeModPythonRequest(ModPythonRequest):
+... def __init__(self, *args, **kwargs):
+... super(FakeModPythonRequest, self).__init__(*args, **kwargs)
+... self._get = self._post = self._meta = self._cookies = {}
+>>> class Dummy: pass
+...
+>>> req = Dummy()
+>>> req.uri = 'bogus'
+>>> print repr(FakeModPythonRequest(req))
+<ModPythonRequest
+path:bogus,
+GET:{},
+POST:{},
+COOKIES:{},
+META:{}>
+"""
Please sign in to comment.
Something went wrong with that request. Please try again.