1
1
from .exceptions_types import EmailSyntaxError
2
2
from .rfc_constants import EMAIL_MAX_LENGTH , LOCAL_PART_MAX_LENGTH , DOMAIN_MAX_LENGTH , \
3
- DOT_ATOM_TEXT , DOT_ATOM_TEXT_INTL , ATEXT , ATEXT_INTL , DNS_LABEL_LENGTH_LIMIT , DOT_ATOM_TEXT_HOSTNAME
3
+ DOT_ATOM_TEXT , DOT_ATOM_TEXT_INTL , ATEXT , ATEXT_INTL , DNS_LABEL_LENGTH_LIMIT , DOT_ATOM_TEXT_HOSTNAME , DOMAIN_NAME_REGEX
4
4
5
5
import re
6
6
import unicodedata
@@ -42,7 +42,7 @@ def validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=Fals
42
42
raise EmailSyntaxError ("The email address is too long before the @-sign {}." .format (reason ))
43
43
44
44
# Check the local part against the regular expression for the older ASCII requirements.
45
- m = re .match (DOT_ATOM_TEXT + " \\ Z" , local )
45
+ m = DOT_ATOM_TEXT .match (local )
46
46
if m :
47
47
# Return the local part unchanged and flag that SMTPUTF8 is not needed.
48
48
return {
@@ -53,7 +53,7 @@ def validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=Fals
53
53
54
54
else :
55
55
# The local part failed the ASCII check. Now try the extended internationalized requirements.
56
- m = re .match (DOT_ATOM_TEXT_INTL + " \\ Z" , local )
56
+ m = DOT_ATOM_TEXT_INTL .match (local )
57
57
if not m :
58
58
# It's not a valid internationalized address either. Report which characters were not valid.
59
59
bad_chars = ', ' .join (sorted (set (
@@ -141,7 +141,7 @@ def validate_email_domain_part(domain, test_environment=False, globally_delivera
141
141
if ".." in domain :
142
142
raise EmailSyntaxError ("An email address cannot have two periods in a row." )
143
143
144
- if re .match (DOT_ATOM_TEXT_HOSTNAME + " \\ Z" , domain ):
144
+ if DOT_ATOM_TEXT_HOSTNAME .match (domain ):
145
145
ascii_domain = domain
146
146
else :
147
147
# If international characters are present in the domain name, convert
@@ -170,7 +170,7 @@ def validate_email_domain_part(domain, test_environment=False, globally_delivera
170
170
171
171
# Check the syntax of the string returned by idna.encode.
172
172
# It should never fail.
173
- m = re .match (DOT_ATOM_TEXT_HOSTNAME + " \\ Z" , ascii_domain )
173
+ m = DOT_ATOM_TEXT_HOSTNAME .match (ascii_domain )
174
174
if not m :
175
175
raise EmailSyntaxError ("The email address contains invalid characters after the @-sign after IDNA encoding." )
176
176
@@ -198,7 +198,7 @@ def validate_email_domain_part(domain, test_environment=False, globally_delivera
198
198
raise EmailSyntaxError ("The part after the @-sign is not valid. It should have a period." )
199
199
200
200
# We also know that all TLDs currently end with a letter.
201
- if not re .search (r"[A-Za-z]\Z" , ascii_domain ):
201
+ if not DOMAIN_NAME_REGEX .search (ascii_domain ):
202
202
raise EmailSyntaxError ("The part after the @-sign is not valid. It is not within a valid top-level domain." )
203
203
204
204
# Check special-use and reserved domain names.
0 commit comments