From 75f107b8842dfc890ddd65262bd09ca87c3a15be Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 18 Nov 2014 11:57:05 -0500 Subject: [PATCH] Removed request.REQUEST per deprecation timeline; refs #18659. --- django/core/handlers/wsgi.py | 11 ----------- docs/ref/request-response.txt | 15 --------------- docs/topics/http/middleware.txt | 11 +++++------ tests/deprecation/tests.py | 22 +--------------------- tests/test_client_regress/tests.py | 15 --------------- tests/test_client_regress/views.py | 6 ------ 6 files changed, 6 insertions(+), 74 deletions(-) diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index b4402686c02..7c94758e86b 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -6,15 +6,12 @@ import logging import sys from io import BytesIO from threading import Lock -import warnings from django import http from django.conf import settings from django.core import signals from django.core.handlers import base from django.core.urlresolvers import set_script_prefix -from django.utils import datastructures -from django.utils.deprecation import RemovedInDjango19Warning from django.utils.encoding import force_str, force_text from django.utils.functional import cached_property from django.utils import six @@ -121,13 +118,6 @@ class WSGIRequest(http.HttpRequest): def _get_scheme(self): return self.environ.get('wsgi.url_scheme') - def _get_request(self): - warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or ' - '`request.POST` instead.', RemovedInDjango19Warning, 2) - if not hasattr(self, '_request'): - self._request = datastructures.MergeDict(self.POST, self.GET) - return self._request - @cached_property def GET(self): # The WSGI spec says 'QUERY_STRING' may be absent. @@ -154,7 +144,6 @@ class WSGIRequest(http.HttpRequest): POST = property(_get_post, _set_post) FILES = property(_get_files) - REQUEST = property(_get_request) class WSGIHandler(base.BaseHandler): diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 1375ba10e53..41e6d3dcdc8 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -108,21 +108,6 @@ All attributes should be considered read-only, unless stated otherwise below. Note: ``POST`` does *not* include file-upload information. See ``FILES``. -.. attribute:: HttpRequest.REQUEST - - .. deprecated:: 1.7 - Use the more explicit ``GET`` and ``POST`` instead. - - For convenience, a dictionary-like object that searches ``POST`` first, - then ``GET``. Inspired by PHP's ``$_REQUEST``. - - For example, if ``GET = {"name": "john"}`` and ``POST = {"age": '34'}``, - ``REQUEST["name"]`` would be ``"john"``, and ``REQUEST["age"]`` would be - ``"34"``. - - It's strongly suggested that you use ``GET`` and ``POST`` instead of - ``REQUEST``, because the former are more explicit. - .. attribute:: HttpRequest.COOKIES A standard Python dictionary containing all cookies. Keys and values are diff --git a/docs/topics/http/middleware.txt b/docs/topics/http/middleware.txt index cc7607da0aa..7e1e01dd872 100644 --- a/docs/topics/http/middleware.txt +++ b/docs/topics/http/middleware.txt @@ -130,12 +130,11 @@ view; it'll apply response middleware to that .. note:: - Accessing :attr:`request.POST ` or - :attr:`request.REQUEST ` inside middleware - from ``process_request`` or ``process_view`` will prevent any view running - after the middleware from being able to :ref:`modify the upload handlers - for the request `, and should - normally be avoided. + Accessing :attr:`request.POST ` inside + middleware from ``process_request`` or ``process_view`` will prevent any + view running after the middleware from being able to :ref:`modify the + upload handlers for the request `, + and should normally be avoided. The :class:`~django.middleware.csrf.CsrfViewMiddleware` class can be considered an exception, as it provides the diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py index cae03a84240..2d9a9beb69a 100644 --- a/tests/deprecation/tests.py +++ b/tests/deprecation/tests.py @@ -4,7 +4,7 @@ import os import unittest import warnings -from django.test import SimpleTestCase, RequestFactory, override_settings +from django.test import SimpleTestCase, override_settings from django.test.utils import reset_warning_registry from django.utils import six, translation from django.utils.deprecation import RenameMethodsBase @@ -175,26 +175,6 @@ class RenameMethodsTests(SimpleTestCase): ]) -class DeprecatingRequestMergeDictTest(SimpleTestCase): - def test_deprecated_request(self): - """ - Ensure the correct warning is raised when WSGIRequest.REQUEST is - accessed. - """ - reset_warning_registry() - with warnings.catch_warnings(record=True) as recorded: - warnings.simplefilter('always') - request = RequestFactory().get('/') - request.REQUEST # evaluate - - msgs = [str(warning.message) for warning in recorded] - self.assertEqual(msgs, [ - '`request.REQUEST` is deprecated, use `request.GET` or ' - '`request.POST` instead.', - '`MergeDict` is deprecated, use `dict.update()` instead.', - ]) - - @override_settings(USE_I18N=True) class DeprecatedChineseLanguageCodes(SimpleTestCase): def test_deprecation_warning(self): diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index e17bf4ef811..1ae94573002 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -953,14 +953,12 @@ class zzUrlconfSubstitutionTests(TestCase): class ContextTests(TestCase): fixtures = ['testdata'] - @ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated def test_single_context(self): "Context variables can be retrieved from a single context" response = self.client.get("/request_data/", data={'foo': 'whiz'}) self.assertEqual(response.context.__class__, Context) self.assertIn('get-foo', response.context) self.assertEqual(response.context['get-foo'], 'whiz') - self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['data'], 'sausage') try: @@ -969,7 +967,6 @@ class ContextTests(TestCase): except KeyError as e: self.assertEqual(e.args[0], 'does-not-exist') - @ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated def test_inherited_context(self): "Context variables can be retrieved from a list of contexts" response = self.client.get("/request_data_extended/", data={'foo': 'whiz'}) @@ -977,7 +974,6 @@ class ContextTests(TestCase): self.assertEqual(len(response.context), 2) self.assertIn('get-foo', response.context) self.assertEqual(response.context['get-foo'], 'whiz') - self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['data'], 'bacon') try: @@ -1252,7 +1248,6 @@ class RequestMethodStringDataTests(TestCase): @override_settings(ROOT_URLCONF='test_client_regress.urls',) class QueryStringTests(TestCase): - @ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated def test_get_like_requests(self): # See: https://code.djangoproject.com/ticket/10571. for method_name in ('get', 'head'): @@ -1260,25 +1255,19 @@ class QueryStringTests(TestCase): method = getattr(self.client, method_name) response = method("/request_data/", data={'foo': 'whiz'}) self.assertEqual(response.context['get-foo'], 'whiz') - self.assertEqual(response.context['request-foo'], 'whiz') # A GET-like request can pass a query string as part of the URL response = method("/request_data/?foo=whiz") self.assertEqual(response.context['get-foo'], 'whiz') - self.assertEqual(response.context['request-foo'], 'whiz') # Data provided in the URL to a GET-like request is overridden by actual form data response = method("/request_data/?foo=whiz", data={'foo': 'bang'}) self.assertEqual(response.context['get-foo'], 'bang') - self.assertEqual(response.context['request-foo'], 'bang') response = method("/request_data/?foo=whiz", data={'bar': 'bang'}) self.assertEqual(response.context['get-foo'], None) self.assertEqual(response.context['get-bar'], 'bang') - self.assertEqual(response.context['request-foo'], None) - self.assertEqual(response.context['request-bar'], 'bang') - @ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated def test_post_like_requests(self): # A POST-like request can pass a query string as data response = self.client.post("/request_data/", data={'foo': 'whiz'}) @@ -1289,21 +1278,17 @@ class QueryStringTests(TestCase): response = self.client.post("/request_data/?foo=whiz") self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['post-foo'], None) - self.assertEqual(response.context['request-foo'], 'whiz') # POST data provided in the URL augments actual form data response = self.client.post("/request_data/?foo=whiz", data={'foo': 'bang'}) self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['post-foo'], 'bang') - self.assertEqual(response.context['request-foo'], 'bang') response = self.client.post("/request_data/?foo=whiz", data={'bar': 'bang'}) self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-bar'], None) self.assertEqual(response.context['post-foo'], None) self.assertEqual(response.context['post-bar'], 'bang') - self.assertEqual(response.context['request-foo'], 'whiz') - self.assertEqual(response.context['request-bar'], 'bang') @override_settings(ROOT_URLCONF='test_client_regress.urls') diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py index 28635940aea..1c5e221a2a2 100644 --- a/tests/test_client_regress/views.py +++ b/tests/test_client_regress/views.py @@ -38,17 +38,11 @@ get_view = login_required(get_view) def request_data(request, template='base.html', data='sausage'): "A simple view that returns the request data in the context" - - request_foo = request.REQUEST.get('foo') - request_bar = request.REQUEST.get('bar') - return render_to_response(template, { 'get-foo': request.GET.get('foo'), 'get-bar': request.GET.get('bar'), 'post-foo': request.POST.get('foo'), 'post-bar': request.POST.get('bar'), - 'request-foo': request_foo, - 'request-bar': request_bar, 'data': data, })