diff options
| author | David Smith <smithdc@gmail.com> | 2020-06-17 07:35:09 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-18 21:43:20 +0200 |
| commit | 27c09043da52ca1f02605bf28600bfd5ace95ae4 (patch) | |
| tree | b9fb0d8d11a736943e4bab5ea2982bb8d96d6477 /django | |
| parent | 26a413507abb38f7eee4cf62f2ee9727fdc7bf8d (diff) | |
Refs #31670 -- Renamed whitelist argument and attribute of EmailValidator.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/validators.py | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/django/core/validators.py b/django/core/validators.py index a37f3416e9..84b4f31ec7 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -1,10 +1,12 @@ import ipaddress import re +import warnings from pathlib import Path from urllib.parse import urlsplit, urlunsplit from django.core.exceptions import ValidationError from django.utils.deconstruct import deconstructible +from django.utils.deprecation import RemovedInDjango41Warning from django.utils.encoding import punycode from django.utils.ipv6 import is_valid_ipv6_address from django.utils.regex_helper import _lazy_re_compile @@ -167,15 +169,42 @@ class EmailValidator: # literal form, ipv4 or ipv6 address (SMTP 4.1.3) r'\[([A-f0-9:.]+)\]\Z', re.IGNORECASE) - domain_whitelist = ['localhost'] + domain_allowlist = ['localhost'] - def __init__(self, message=None, code=None, whitelist=None): + @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, + ) if message is not None: self.message = message if code is not None: self.code = code - if whitelist is not None: - self.domain_whitelist = whitelist + if allowlist is not None: + self.domain_allowlist = allowlist def __call__(self, value): if not value or '@' not in value: @@ -186,7 +215,7 @@ class EmailValidator: if not self.user_regex.match(user_part): raise ValidationError(self.message, code=self.code) - if (domain_part not in self.domain_whitelist and + if (domain_part not in self.domain_allowlist and not self.validate_domain_part(domain_part)): # Try for possible IDN domain-part try: @@ -215,7 +244,7 @@ class EmailValidator: def __eq__(self, other): return ( isinstance(other, EmailValidator) and - (self.domain_whitelist == other.domain_whitelist) and + (self.domain_allowlist == other.domain_allowlist) and (self.message == other.message) and (self.code == other.code) ) |
