2
0
Эх сурвалжийг харах

Refs #31670 -- Removed whitelist argument and domain_whitelist attribute in EmailValidator per deprecation timeline.

Mariusz Felisiak 3 жил өмнө
parent
commit
d25710a625

+ 1 - 30
django/core/validators.py

@@ -1,12 +1,10 @@
 import ipaddress
 import ipaddress
 import re
 import re
-import warnings
 from pathlib import Path
 from pathlib import Path
 from urllib.parse import urlsplit, urlunsplit
 from urllib.parse import urlsplit, urlunsplit
 
 
 from django.core.exceptions import ValidationError
 from django.core.exceptions import ValidationError
 from django.utils.deconstruct import deconstructible
 from django.utils.deconstruct import deconstructible
-from django.utils.deprecation import RemovedInDjango41Warning
 from django.utils.encoding import punycode
 from django.utils.encoding import punycode
 from django.utils.ipv6 import is_valid_ipv6_address
 from django.utils.ipv6 import is_valid_ipv6_address
 from django.utils.regex_helper import _lazy_re_compile
 from django.utils.regex_helper import _lazy_re_compile
@@ -174,34 +172,7 @@ class EmailValidator:
         re.IGNORECASE)
         re.IGNORECASE)
     domain_allowlist = ['localhost']
     domain_allowlist = ['localhost']
 
 
-    @property
-    def domain_whitelist(self):
-        warnings.warn(
-            'The domain_whitelist attribute is deprecated in favor of '
-            'domain_allowlist.',
-            RemovedInDjango41Warning,
-            stacklevel=2,
-        )
-        return self.domain_allowlist
-
-    @domain_whitelist.setter
-    def domain_whitelist(self, allowlist):
-        warnings.warn(
-            'The domain_whitelist attribute is deprecated in favor of '
-            'domain_allowlist.',
-            RemovedInDjango41Warning,
-            stacklevel=2,
-        )
-        self.domain_allowlist = allowlist
-
-    def __init__(self, message=None, code=None, allowlist=None, *, whitelist=None):
-        if whitelist is not None:
-            allowlist = whitelist
-            warnings.warn(
-                'The whitelist argument is deprecated in favor of allowlist.',
-                RemovedInDjango41Warning,
-                stacklevel=2,
-            )
+    def __init__(self, message=None, code=None, allowlist=None):
         if message is not None:
         if message is not None:
             self.message = message
             self.message = message
         if code is not None:
         if code is not None:

+ 0 - 7
docs/ref/validators.txt

@@ -151,13 +151,6 @@ to, or in lieu of custom ``field.clean()`` methods.
         validation, so you'd need to add them to the ``allowlist`` as
         validation, so you'd need to add them to the ``allowlist`` as
         necessary.
         necessary.
 
 
-    .. deprecated:: 3.2
-
-        The ``whitelist`` parameter is deprecated. Use :attr:`allowlist`
-        instead.
-        The undocumented ``domain_whitelist`` attribute is deprecated. Use
-        ``domain_allowlist`` instead.
-
 ``URLValidator``
 ``URLValidator``
 ----------------
 ----------------
 
 

+ 3 - 0
docs/releases/4.1.txt

@@ -252,3 +252,6 @@ to remove usage of these features.
 
 
 * Support for using a boolean value in
 * Support for using a boolean value in
   :attr:`.BaseCommand.requires_system_checks` is removed.
   :attr:`.BaseCommand.requires_system_checks` is removed.
+
+* The ``whitelist`` argument and ``domain_whitelist`` attribute of
+  ``django.core.validators.EmailValidator`` are removed.

+ 1 - 41
tests/validators/tests.py

@@ -15,8 +15,7 @@ from django.core.validators import (
     validate_ipv4_address, validate_ipv6_address, validate_ipv46_address,
     validate_ipv4_address, validate_ipv6_address, validate_ipv46_address,
     validate_slug, validate_unicode_slug,
     validate_slug, validate_unicode_slug,
 )
 )
-from django.test import SimpleTestCase, ignore_warnings
-from django.utils.deprecation import RemovedInDjango41Warning
+from django.test import SimpleTestCase
 
 
 try:
 try:
     from PIL import Image  # noqa
     from PIL import Image  # noqa
@@ -738,42 +737,3 @@ class TestValidatorEquality(TestCase):
             ProhibitNullCharactersValidator(message='message', code='code1'),
             ProhibitNullCharactersValidator(message='message', code='code1'),
             ProhibitNullCharactersValidator(message='message', code='code2')
             ProhibitNullCharactersValidator(message='message', code='code2')
         )
         )
-
-
-class DeprecationTests(SimpleTestCase):
-    @ignore_warnings(category=RemovedInDjango41Warning)
-    def test_whitelist(self):
-        validator = EmailValidator(whitelist=['localdomain'])
-        self.assertEqual(validator.domain_allowlist, ['localdomain'])
-        self.assertIsNone(validator('email@localdomain'))
-        self.assertEqual(validator.domain_allowlist, validator.domain_whitelist)
-
-    def test_whitelist_warning(self):
-        msg = "The whitelist argument is deprecated in favor of allowlist."
-        with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
-            EmailValidator(whitelist='localdomain')
-
-    @ignore_warnings(category=RemovedInDjango41Warning)
-    def test_domain_whitelist(self):
-        validator = EmailValidator()
-        validator.domain_whitelist = ['mydomain']
-        self.assertEqual(validator.domain_allowlist, ['mydomain'])
-        self.assertEqual(validator.domain_allowlist, validator.domain_whitelist)
-
-    def test_domain_whitelist_access_warning(self):
-        validator = EmailValidator()
-        msg = (
-            'The domain_whitelist attribute is deprecated in favor of '
-            'domain_allowlist.'
-        )
-        with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
-            validator.domain_whitelist
-
-    def test_domain_whitelist_set_warning(self):
-        validator = EmailValidator()
-        msg = (
-            'The domain_whitelist attribute is deprecated in favor of '
-            'domain_allowlist.'
-        )
-        with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
-            validator.domain_whitelist = ['mydomain']