diff --git a/django/http/__init__.py b/django/http/__init__.py
index c6bf2f1..2b96d04 100644
a
|
b
|
class Http404(Exception):
|
127 | 127 | |
128 | 128 | RAISE_ERROR = object() |
129 | 129 | |
| 130 | class 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 |
130 | 137 | |
131 | 138 | def build_request_repr(request, path_override=None, GET_override=None, |
132 | 139 | POST_override=None, COOKIES_override=None, |
… |
… |
class HttpRequest(object):
|
301 | 308 | def _get_raw_post_data(self): |
302 | 309 | if not hasattr(self, '_raw_post_data'): |
303 | 310 | 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") |
305 | 312 | self._raw_post_data = self.read() |
306 | 313 | self._stream = StringIO(self._raw_post_data) |
307 | 314 | return self._raw_post_data |
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py
index e96f312..4087181 100644
a
|
b
|
from StringIO import StringIO
|
5 | 5 | from django.conf import settings |
6 | 6 | from django.core.handlers.modpython import ModPythonRequest |
7 | 7 | from django.core.handlers.wsgi import WSGIRequest, LimitedStream |
8 | | from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr |
| 8 | from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr, RawPostDataException |
9 | 9 | from django.utils import unittest |
10 | 10 | from django.utils.http import cookie_date |
11 | 11 | |
… |
… |
class RequestsTests(unittest.TestCase):
|
314 | 314 | 'CONTENT_LENGTH': len(payload), |
315 | 315 | 'wsgi.input': StringIO(payload)}) |
316 | 316 | self.assertEqual(request.read(2), 'na') |
317 | | self.assertRaises(Exception, lambda: request.raw_post_data) |
| 317 | self.assertRaises(RawPostDataException, lambda: request.raw_post_data) |
318 | 318 | self.assertEqual(request.POST, {}) |
319 | 319 | |
320 | 320 | def test_raw_post_data_after_POST_multipart(self): |
… |
… |
class RequestsTests(unittest.TestCase):
|
336 | 336 | 'CONTENT_LENGTH': len(payload), |
337 | 337 | 'wsgi.input': StringIO(payload)}) |
338 | 338 | 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) |
340 | 340 | |
341 | 341 | def test_POST_multipart_with_content_length_zero(self): |
342 | 342 | """ |