Ticket #16822: rawpostdata.patch

File rawpostdata.patch, 2.7 KB (added by James Aylett, 13 years ago)

Specific exception patch including test changes

  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index c6bf2f1..2b96d04 100644
    a b class Http404(Exception):  
    127127
    128128RAISE_ERROR = object()
    129129
     130class RawPostDataException(Exception):
     131    """
     132    You cannot access raw_post_data from a request that has
     133    multipart/* POST data if it has been accessed via POST,
     134    FILES etc..
     135    """
     136    pass
    130137
    131138def build_request_repr(request, path_override=None, GET_override=None,
    132139                       POST_override=None, COOKIES_override=None,
    class HttpRequest(object):  
    301308    def _get_raw_post_data(self):
    302309        if not hasattr(self, '_raw_post_data'):
    303310            if self._read_started:
    304                 raise Exception("You cannot access raw_post_data after reading from request's data stream")
     311                raise RawPostDataException("You cannot access raw_post_data after reading from request's data stream")
    305312            self._raw_post_data = self.read()
    306313            self._stream = StringIO(self._raw_post_data)
    307314        return self._raw_post_data
  • tests/regressiontests/requests/tests.py

    diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py
    index e96f312..4087181 100644
    a b from StringIO import StringIO  
    55from django.conf import settings
    66from django.core.handlers.modpython import ModPythonRequest
    77from django.core.handlers.wsgi import WSGIRequest, LimitedStream
    8 from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr
     8from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr, RawPostDataException
    99from django.utils import unittest
    1010from django.utils.http import cookie_date
    1111
    class RequestsTests(unittest.TestCase):  
    314314                               'CONTENT_LENGTH': len(payload),
    315315                               'wsgi.input': StringIO(payload)})
    316316        self.assertEqual(request.read(2), 'na')
    317         self.assertRaises(Exception, lambda: request.raw_post_data)
     317        self.assertRaises(RawPostDataException, lambda: request.raw_post_data)
    318318        self.assertEqual(request.POST, {})
    319319
    320320    def test_raw_post_data_after_POST_multipart(self):
    class RequestsTests(unittest.TestCase):  
    336336                               'CONTENT_LENGTH': len(payload),
    337337                               'wsgi.input': StringIO(payload)})
    338338        self.assertEqual(request.POST, {u'name': [u'value']})
    339         self.assertRaises(Exception, lambda: request.raw_post_data)
     339        self.assertRaises(RawPostDataException, lambda: request.raw_post_data)
    340340
    341341    def test_POST_multipart_with_content_length_zero(self):
    342342        """
Back to Top