Skip to content

Commit d38aab3

Browse files
Remove unused code
1 parent 82d91a8 commit d38aab3

File tree

13 files changed

+19
-97
lines changed

13 files changed

+19
-97
lines changed

rest_framework/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
\_| \_\____/\____/ \_/ |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_|
88
"""
99

10-
import django
11-
1210
__title__ = 'Django REST framework'
1311
__version__ = '3.15.1'
1412
__author__ = 'Tom Christie'
@@ -25,10 +23,6 @@
2523
ISO_8601 = 'iso-8601'
2624

2725

28-
if django.VERSION < (3, 2):
29-
default_app_config = 'rest_framework.apps.RestFrameworkConfig'
30-
31-
3226
class RemovedInDRF315Warning(DeprecationWarning):
3327
pass
3428

rest_framework/authtoken/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
import django
2-
3-
if django.VERSION < (3, 2):
4-
default_app_config = 'rest_framework.authtoken.apps.AuthTokenConfig'

rest_framework/compat.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,6 @@ def md_filter_add_syntax_highlight(md):
151151
return False
152152

153153

154-
if django.VERSION >= (4, 2):
155-
# Django 4.2+: use the stock parse_header_parameters function
156-
# Note: Django 4.1 also has an implementation of parse_header_parameters
157-
# which is slightly different from the one in 4.2, it needs
158-
# the compatibility shim as well.
159-
from django.utils.http import parse_header_parameters
160-
else:
161-
# Django <= 4.1: create a compatibility shim for parse_header_parameters
162-
from django.http.multipartparser import parse_header
163-
164-
def parse_header_parameters(line):
165-
# parse_header works with bytes, but parse_header_parameters
166-
# works with strings. Call encode to convert the line to bytes.
167-
main_value_pair, params = parse_header(line.encode())
168-
return main_value_pair, {
169-
# parse_header will convert *some* values to string.
170-
# parse_header_parameters converts *all* values to string.
171-
# Make sure all values are converted by calling decode on
172-
# any remaining non-string values.
173-
k: v if isinstance(v, str) else v.decode()
174-
for k, v in params.items()
175-
}
176-
177-
178154
if django.VERSION >= (5, 1):
179155
# Django 5.1+: use the stock ip_address_validators function
180156
# Note: Before Django 5.1, ip_address_validators returns a tuple containing

rest_framework/filters.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ def construct_search(self, field_name, queryset):
114114
if hasattr(field, "path_infos"):
115115
# Update opts to follow the relation.
116116
opts = field.path_infos[-1].to_opts
117-
# django < 4.1
118-
elif hasattr(field, 'get_path_info'):
119-
# Update opts to follow the relation.
120-
opts = field.get_path_info()[-1].to_opts
121117
# Otherwise, use the field with icontains.
122118
lookup = 'icontains'
123119
return LOOKUP_SEP.join([field_name, lookup])

rest_framework/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from django.http.multipartparser import \
1616
MultiPartParser as DjangoMultiPartParser
1717
from django.http.multipartparser import MultiPartParserError
18+
from django.utils.http import parse_header_parameters
1819

1920
from rest_framework import renderers
20-
from rest_framework.compat import parse_header_parameters
2121
from rest_framework.exceptions import ParseError
2222
from rest_framework.settings import api_settings
2323
from rest_framework.utils import json

rest_framework/renderers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
from django.template import engines, loader
2020
from django.urls import NoReverseMatch
2121
from django.utils.html import mark_safe
22+
from django.utils.http import parse_header_parameters
2223
from django.utils.safestring import SafeString
2324

2425
from rest_framework import VERSION, exceptions, serializers, status
2526
from rest_framework.compat import (
2627
INDENT_SEPARATORS, LONG_SEPARATORS, SHORT_SEPARATORS, coreapi, coreschema,
27-
parse_header_parameters, pygments_css, yaml
28+
pygments_css, yaml
2829
)
2930
from rest_framework.exceptions import ParseError
3031
from rest_framework.request import is_form_media_type, override_method

rest_framework/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from django.http import HttpRequest, QueryDict
1717
from django.http.request import RawPostDataException
1818
from django.utils.datastructures import MultiValueDict
19+
from django.utils.http import parse_header_parameters
1920

2021
from rest_framework import exceptions
21-
from rest_framework.compat import parse_header_parameters
2222
from rest_framework.settings import api_settings
2323

2424

rest_framework/test.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io
44
from importlib import import_module
55

6-
import django
76
from django.conf import settings
87
from django.core.exceptions import ImproperlyConfigured
98
from django.core.handlers.wsgi import WSGIHandler
@@ -394,19 +393,7 @@ def setUpClass(cls):
394393

395394
cls._override.enable()
396395

397-
if django.VERSION > (4, 0):
398-
cls.addClassCleanup(cls._override.disable)
399-
cls.addClassCleanup(cleanup_url_patterns, cls)
396+
cls.addClassCleanup(cls._override.disable)
397+
cls.addClassCleanup(cleanup_url_patterns, cls)
400398

401399
super().setUpClass()
402-
403-
if django.VERSION < (4, 0):
404-
@classmethod
405-
def tearDownClass(cls):
406-
super().tearDownClass()
407-
cls._override.disable()
408-
409-
if hasattr(cls, '_module_urlpatterns'):
410-
cls._module.urlpatterns = cls._module_urlpatterns
411-
else:
412-
del cls._module.urlpatterns

rest_framework/utils/mediatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
See https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
55
"""
6-
from rest_framework.compat import parse_header_parameters
6+
from django.utils.http import parse_header_parameters
77

88

99
def media_type_matches(lhs, rhs):

tests/authentication/test_authentication.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import base64
22

3-
import django
43
import pytest
54
from django.conf import settings
65
from django.contrib.auth.models import User
@@ -235,21 +234,13 @@ def test_post_form_session_auth_passing_csrf(self):
235234
Ensure POSTing form over session authentication with CSRF token succeeds.
236235
Regression test for #6088
237236
"""
238-
# Remove this shim when dropping support for Django 3.0.
239-
if django.VERSION < (3, 1):
240-
from django.middleware.csrf import _get_new_csrf_token
241-
else:
242-
from django.middleware.csrf import (
243-
_get_new_csrf_string, _mask_cipher_secret
244-
)
245-
246-
def _get_new_csrf_token():
247-
return _mask_cipher_secret(_get_new_csrf_string())
248-
249237
self.csrf_client.login(username=self.username, password=self.password)
250238

251239
# Set the csrf_token cookie so that CsrfViewMiddleware._get_token() works
252-
token = _get_new_csrf_token()
240+
from django.middleware.csrf import (
241+
_get_new_csrf_string, _mask_cipher_secret
242+
)
243+
token = _mask_cipher_secret(_get_new_csrf_string())
253244
self.csrf_client.cookies[settings.CSRF_COOKIE_NAME] = token
254245

255246
# Post the token matching the cookie value

tests/conftest.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ def pytest_addoption(parser):
1313
def pytest_configure(config):
1414
from django.conf import settings
1515

16-
# USE_L10N is deprecated, and will be removed in Django 5.0.
17-
use_l10n = {"USE_L10N": True} if django.VERSION < (4, 0) else {}
1816
settings.configure(
1917
DEBUG_PROPAGATE_EXCEPTIONS=True,
2018
DATABASES={
@@ -64,7 +62,6 @@ def pytest_configure(config):
6462
PASSWORD_HASHERS=(
6563
'django.contrib.auth.hashers.MD5PasswordHasher',
6664
),
67-
**use_l10n,
6865
)
6966

7067
# guardian is optional
@@ -87,10 +84,7 @@ def pytest_configure(config):
8784
import rest_framework
8885
settings.STATIC_ROOT = os.path.join(os.path.dirname(rest_framework.__file__), 'static-root')
8986
backend = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
90-
if django.VERSION < (4, 2):
91-
settings.STATICFILES_STORAGE = backend
92-
else:
93-
settings.STORAGES['staticfiles']['BACKEND'] = backend
87+
settings.STORAGES['staticfiles']['BACKEND'] = backend
9488

9589
django.setup()
9690

tests/test_model_serializer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import sys
1313
import tempfile
1414

15-
import django
1615
import pytest
1716
from django.core.exceptions import ImproperlyConfigured
1817
from django.core.serializers.json import DjangoJSONEncoder
@@ -453,14 +452,11 @@ class Meta:
453452
model = ArrayFieldModel
454453
fields = ['array_field', 'array_field_with_blank']
455454

456-
validators = ""
457-
if django.VERSION < (4, 1):
458-
validators = ", validators=[<django.core.validators.MaxLengthValidator object>]"
459455
expected = dedent("""
460456
TestSerializer():
461-
array_field = ListField(allow_empty=False, child=CharField(label='Array field'%s))
462-
array_field_with_blank = ListField(child=CharField(label='Array field with blank'%s), required=False)
463-
""" % (validators, validators))
457+
array_field = ListField(allow_empty=False, child=CharField(label='Array field'))
458+
array_field_with_blank = ListField(child=CharField(label='Array field with blank'), required=False)
459+
""")
464460
self.assertEqual(repr(TestSerializer()), expected)
465461

466462
@pytest.mark.skipif(hasattr(models, 'JSONField'), reason='has models.JSONField')

tests/test_testing.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from io import BytesIO
33
from unittest.mock import patch
44

5-
import django
65
from django.contrib.auth.models import User
76
from django.http import HttpResponseRedirect
87
from django.shortcuts import redirect
@@ -334,18 +333,10 @@ def setUpClass(cls):
334333
super().setUpClass()
335334
assert urlpatterns is cls.urlpatterns
336335

337-
if django.VERSION > (4, 0):
338-
cls.addClassCleanup(
339-
check_urlpatterns,
340-
cls
341-
)
342-
343-
if django.VERSION < (4, 0):
344-
@classmethod
345-
def tearDownClass(cls):
346-
assert urlpatterns is cls.urlpatterns
347-
super().tearDownClass()
348-
assert urlpatterns is not cls.urlpatterns
336+
cls.addClassCleanup(
337+
check_urlpatterns,
338+
cls
339+
)
349340

350341
def test_urlpatterns(self):
351342
assert self.client.get('/').status_code == 200

0 commit comments

Comments
 (0)