From 0863667835e830f6d84a409f256bb879e38fa684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Daniel?= Date: Tue, 20 Feb 2024 17:17:39 +0100 Subject: [PATCH] chore: Django bump to <=5.0 --- docs/throttling.rst | 4 ++-- example/apps/test_security/tests/input_request_log.py | 4 ++-- example/urls.py | 2 +- security/backends/common/is_core.py | 2 +- security/backends/elasticsearch/is_core/cores.py | 2 +- security/backends/elasticsearch/is_core/filters.py | 8 ++++---- security/backends/sql/is_core/cores.py | 2 +- security/backends/sql/is_core/filters.py | 4 ++-- security/backends/sql/models.py | 4 ++-- security/backends/testing/__init__.py | 2 -- security/logging/requests/utils.py | 6 +++--- security/throttling/validators.py | 2 +- security/throttling/views.py | 4 ++-- setup.py | 6 +----- 14 files changed, 23 insertions(+), 29 deletions(-) diff --git a/docs/throttling.rst b/docs/throttling.rst index 925557a2..287207de 100644 --- a/docs/throttling.rst +++ b/docs/throttling.rst @@ -58,10 +58,10 @@ View If ``security.throttling.exception.ThrottlingException`` is raised the specific error view is returned. You can change it with only overriding template named 429.html in your templates. With setting ``SECURITY_THROTTLING_FAILURE_VIEW`` you can change view function which default code is:: from django.shortcuts import render - from django.utils.encoding import force_text + from django.utils.encoding import force_str def throttling_failure_view(request, exception): - response = render(request, '429.html', {'description': force_text(exception)}) + response = render(request, '429.html', {'description': force_str(exception)}) response.status_code = 429 return response diff --git a/example/apps/test_security/tests/input_request_log.py b/example/apps/test_security/tests/input_request_log.py index 956e59a6..11a20c3e 100644 --- a/example/apps/test_security/tests/input_request_log.py +++ b/example/apps/test_security/tests/input_request_log.py @@ -4,7 +4,7 @@ from django import get_version from django.test import override_settings -from django.utils.encoding import force_text +from django.utils.encoding import force_str from germanium.decorators import data_consumer from germanium.test_cases.client import ClientTestCase @@ -186,7 +186,7 @@ def test_request_body_truncation_should_be_turned_off(self): def test_response_body_truncation_should_be_turned_off(self): with capture_security_logs() as logged_data: response = self.post('/admin/login/', data={'username': 2000 * 'a', 'password': 2000 * 'b'}) - assert_equal(logged_data.input_request[0].response_body, force_text(response.content)) + assert_equal(logged_data.input_request[0].response_body, force_str(response.content)) assert_false(logged_data.input_request[0].response_body.endswith(TRUNCATION_CHAR)) @override_settings(SECURITY_LOG_RESPONSE_BODY_CONTENT_TYPES=()) diff --git a/example/urls.py b/example/urls.py index 5d6753f3..5fca684e 100644 --- a/example/urls.py +++ b/example/urls.py @@ -5,7 +5,7 @@ error_view ) -from django.conf.urls import url +from django.conf.urls import re_path as url urlpatterns = [ diff --git a/security/backends/common/is_core.py b/security/backends/common/is_core.py index b72043c5..d14457c3 100644 --- a/security/backends/common/is_core.py +++ b/security/backends/common/is_core.py @@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType from django.template.defaultfilters import truncatechars -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.utils.html import mark_safe from chamber.shortcuts import get_object_or_none diff --git a/security/backends/elasticsearch/is_core/cores.py b/security/backends/elasticsearch/is_core/cores.py index 1f37217d..288ac395 100644 --- a/security/backends/elasticsearch/is_core/cores.py +++ b/security/backends/elasticsearch/is_core/cores.py @@ -1,4 +1,4 @@ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pyston.utils.decorators import filter_class, order_by diff --git a/security/backends/elasticsearch/is_core/filters.py b/security/backends/elasticsearch/is_core/filters.py index be21ee41..40724791 100644 --- a/security/backends/elasticsearch/is_core/filters.py +++ b/security/backends/elasticsearch/is_core/filters.py @@ -2,7 +2,7 @@ from django.db import router from django.db.models import TextField from django.db.models.functions import Cast -from django.utils.translation import ugettext +from django.utils.translation import gettext from django.contrib.contenttypes.models import ContentType from elasticsearch_dsl import Q @@ -30,7 +30,7 @@ def clean_value(self, value, operator_slug, request): ) if queryset[:settings.ELASTICSEARCH_MAX_NUMBER_OF_TERMS].count() > settings.ELASTICSEARCH_MAX_NUMBER_OF_TERMS: - raise FilterValueError(ugettext('Too many users found for specified username.')) + raise FilterValueError(gettext('Too many users found for specified username.')) return list(queryset.values_list('str_id', flat=True)) @@ -54,7 +54,7 @@ def clean_value(self, value, operator_slug, request): return self._enum[value] except KeyError: raise FilterValueError( - ugettext('Invalid value. Please use one of the following values: {}.').format( + gettext('Invalid value. Please use one of the following values: {}.').format( ', '.join([a.name for a in self._enum]) ) ) @@ -88,7 +88,7 @@ def clean_value(self, value, operator_slug, request): get_key_from_content_type_object_id_and_model_db(model_db, content_type_id, object_id) ) except (ValueError, ContentType.DoesNotExist): - raise FilterValueError(ugettext('Invalid value.')) + raise FilterValueError(gettext('Invalid value.')) return cleaned_values def get_filter_term(self, value, operator_slug, request): diff --git a/security/backends/sql/is_core/cores.py b/security/backends/sql/is_core/cores.py index 131004dd..5834db7e 100644 --- a/security/backends/sql/is_core/cores.py +++ b/security/backends/sql/is_core/cores.py @@ -1,5 +1,5 @@ from django.core.exceptions import ObjectDoesNotExist -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pyston.utils.decorators import filter_class, order_by diff --git a/security/backends/sql/is_core/filters.py b/security/backends/sql/is_core/filters.py index 50acdd45..fc288f93 100644 --- a/security/backends/sql/is_core/filters.py +++ b/security/backends/sql/is_core/filters.py @@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model from django.db.models import TextField, Q from django.db.models.functions import Cast -from django.utils.translation import ugettext +from django.utils.translation import gettext from django.contrib.contenttypes.models import ContentType from pyston.filters.django_filters import SimpleMethodFilter @@ -41,7 +41,7 @@ def clean_value(self, value, operator_slug, request): content_type_id, object_id = v.split('|') cleaned_values.append((int(content_type_id), object_id)) except (ValueError, ContentType.DoesNotExist): - raise FilterValueError(ugettext('Invalid value.')) + raise FilterValueError(gettext('Invalid value.')) return cleaned_values def get_filter_term(self, value, operator_slug, request): diff --git a/security/backends/sql/models.py b/security/backends/sql/models.py index 7377ec0f..0fce5192 100644 --- a/security/backends/sql/models.py +++ b/security/backends/sql/models.py @@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.db import models -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.utils.functional import cached_property from django.utils.timezone import localtime @@ -162,7 +162,7 @@ class RequestLog(Log): def __str__(self): return ' '.join( - (force_text(v) for v in ( + (force_str(v) for v in ( self.slug, self.response_code, localtime(self.start.replace(microsecond=0)) ) if v) ) diff --git a/security/backends/testing/__init__.py b/security/backends/testing/__init__.py index 2cba9510..7abce176 100644 --- a/security/backends/testing/__init__.py +++ b/security/backends/testing/__init__.py @@ -1,3 +1 @@ from .writer import capture_security_logs # noqa: F401 - -default_app_config = 'security.backends.testing.app.SecurityTestingBackend' diff --git a/security/logging/requests/utils.py b/security/logging/requests/utils.py index 51ca6911..2be8044b 100644 --- a/security/logging/requests/utils.py +++ b/security/logging/requests/utils.py @@ -6,7 +6,7 @@ from json import JSONDecodeError from django.template.defaultfilters import truncatechars -from django.utils.encoding import force_text +from django.utils.encoding import force_str from security.config import settings from security.utils import remove_nul_from_string @@ -88,7 +88,7 @@ def truncate_json_data(data): def truncate_body(content, max_length): - content = force_text(content, errors='replace') + content = force_str(content, errors='replace') if len(content) > max_length: try: json_content = json.loads(content) @@ -106,7 +106,7 @@ def truncate_body(content, max_length): def clean_body(body, max_length): if body is None: return body - body = force_text(body, errors='replace') + body = force_str(body, errors='replace') cleaned_body = truncatechars( truncate_body(body, max_length), max_length + len(settings.SENSITIVE_DATA_REPLACEMENT) ) if max_length is not None else str(body) diff --git a/security/throttling/validators.py b/security/throttling/validators.py index e8302786..f72d656d 100644 --- a/security/throttling/validators.py +++ b/security/throttling/validators.py @@ -1,7 +1,7 @@ from datetime import timedelta from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.urls import resolve, Resolver404 from ipware.ip import get_client_ip diff --git a/security/throttling/views.py b/security/throttling/views.py index cfc990d3..8f900d18 100644 --- a/security/throttling/views.py +++ b/security/throttling/views.py @@ -1,8 +1,8 @@ from django.shortcuts import render -from django.utils.encoding import force_text +from django.utils.encoding import force_str def throttling_failure_view(request, exception): - response = render(request, '429.html', {'description': force_text(exception)}) + response = render(request, '429.html', {'description': force_str(exception)}) response.status_code = 429 return response diff --git a/setup.py b/setup.py index 4d228707..3df07836 100644 --- a/setup.py +++ b/setup.py @@ -37,13 +37,9 @@ def read(fname): 'Topic :: Internet :: WWW/HTTP :: Site Management', ], install_requires=[ - 'django>=3.1,<4.0', + 'django>=3.1,<5.0', 'django-ipware>=3.0.2', 'ansi2html>=1.6.0', - 'skip-django-chamber>=0.6.16.3', - 'skip-django-choice-enumfields>=1.1.3.2', - 'skip-django-generic-m2m-field>=0.0.9.3', - 'skip-django-celery-extensions>=0.0.37.1', 'isodate>=0.6.1', ], zip_safe=False