Ticket #5595: 5595.diff

File 5595.diff, 2.7 KB (added by Gary Wilson, 17 years ago)

made use of smart_str in ModPythonRequest repr

  • tests/regressiontests/requests/__init__.py

    === added directory 'tests/regressiontests/requests'
    === added file 'tests/regressiontests/requests/__init__.py'
     
     1"""
     2Tests for Django's various Request objects.
     3"""
  • tests/regressiontests/requests/models.py

    === added file 'tests/regressiontests/requests/models.py'
     
     1# Need a models module for the test runner.
  • tests/regressiontests/requests/tests.py

    === added file 'tests/regressiontests/requests/tests.py'
     
     1"""
     2>>> from django.http import HttpRequest
     3>>> print repr(HttpRequest())
     4<HttpRequest
     5GET:{},
     6POST:{},
     7COOKIES:{},
     8META:{}>
     9
     10>>> from django.core.handlers.wsgi import WSGIRequest
     11>>> print repr(WSGIRequest({'PATH_INFO': 'bogus', 'REQUEST_METHOD': 'bogus'}))
     12<WSGIRequest
     13GET:<QueryDict: {}>,
     14POST:<QueryDict: {}>,
     15COOKIES:{},
     16META:{'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
     29path:bogus,
     30GET:{},
     31POST:{},
     32COOKIES:{},
     33META:{}>
     34"""
  • django/core/handlers/modpython.py

    === modified file 'django/core/handlers/modpython.py'
     
    22from django.core import signals
    33from django.dispatch import dispatcher
    44from django.utils import datastructures
    5 from django.utils.encoding import force_unicode
     5from django.utils.encoding import force_unicode, smart_str
    66from django import http
    77from pprint import pformat
    88import os
     
    3535            meta = pformat(self.META)
    3636        except:
    3737            meta = '<could not parse>'
    38         return '<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
    39             (self.path, get, post, cookies, meta)
     38        return smart_str(u'<ModPythonRequest\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' %
     39                         (self.path, unicode(get), unicode(post),
     40                          unicode(cookies), unicode(meta)))
    4041
    4142    def get_full_path(self):
    4243        return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
Back to Top