Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: tests/test_email.py
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/tests/test_email.py b/tests/test_email.py
- --- a/tests/test_email.py (revision 66726ef806ea2940870251b587a1ae07be9bc1af)
- +++ b/tests/test_email.py (revision afc778de29e4480f8f95b0517b385ed3728b370c)
- @@ -20,6 +20,14 @@
- assert email(value, whitelist=whitelist)
- [email protected](('value', 'local_characters_in_user'), [
- + ('emł[email protected]', "ł"),
- + ('łemł[email protected]', "ł"),
- +])
- +def test_returns_true_on_valid_email_with_local_characters_in_user(value, local_characters_in_user):
- + assert email(value, local_characters_in_user=local_characters_in_user)
- +
- +
- @pytest.mark.parametrize(('value',), [
- (None,),
- ('',),
- Index: validators/email.py
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/validators/email.py b/validators/email.py
- --- a/validators/email.py (revision 66726ef806ea2940870251b587a1ae07be9bc1af)
- +++ b/validators/email.py (revision afc778de29e4480f8f95b0517b385ed3728b370c)
- @@ -1,29 +1,34 @@
- import re
- from .utils import validator
- +from functools import cache
- -user_regex = re.compile(
- - # dot-atom
- - r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+"
- - r"(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$"
- - # quoted-string
- - r'|^"([\001-\010\013\014\016-\037!#-\[\]-77]|'
- - r"""\\[\001-\011\013\014\016-77])*"$)""",
- - re.IGNORECASE
- -)
- -domain_regex = re.compile(
- - # domain
- - r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+'
- - r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)'
- - # literal form, ipv4 address (SMTP 4.1.3)
- - r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)'
- - r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$',
- - re.IGNORECASE)
- +
- +@cache
- +def regex(local_characters_in_user=""):
- + return re.compile(
- + # dot-atom
- + r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z" + local_characters_in_user + "]+"
- + r"(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z" + local_characters_in_user + "]+)*$"
- + # quoted-string
- + r'|^"([\001-\010\013\014\016-\037!#-\[\]-77]|'
- + r"""\\[\001-\011\013\014\016-77])*"$)""",
- + re.IGNORECASE
- + ), re.compile(
- + # domain
- + r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+'
- + r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)'
- + # literal form, ipv4 address (SMTP 4.1.3)
- + r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)'
- + r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$',
- + re.IGNORECASE)
- +
- +
- domain_whitelist = ['localhost']
- @validator
- -def email(value, whitelist=None):
- +def email(value, whitelist=None, local_characters_in_user=""):
- """
- Validate an email address.
- @@ -46,10 +51,12 @@
- :param value: value to validate
- :param whitelist: domain names to whitelist
- + :param local_characters_in_user: string with extra accepted characters in user part
- :copyright: (c) Django Software Foundation and individual contributors.
- :license: BSD
- """
- + user_regex, domain_regex = regex(local_characters_in_user)
- if whitelist is None:
- whitelist = domain_whitelist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement