11from .exceptions_types import EmailSyntaxError
22from .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
44
55import re
66import unicodedata
@@ -42,7 +42,7 @@ def validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=Fals
4242 raise EmailSyntaxError ("The email address is too long before the @-sign {}." .format (reason ))
4343
4444 # 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 )
4646 if m :
4747 # Return the local part unchanged and flag that SMTPUTF8 is not needed.
4848 return {
@@ -53,7 +53,7 @@ def validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=Fals
5353
5454 else :
5555 # 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 )
5757 if not m :
5858 # It's not a valid internationalized address either. Report which characters were not valid.
5959 bad_chars = ', ' .join (sorted (set (
@@ -141,7 +141,7 @@ def validate_email_domain_part(domain, test_environment=False, globally_delivera
141141 if ".." in domain :
142142 raise EmailSyntaxError ("An email address cannot have two periods in a row." )
143143
144- if re .match (DOT_ATOM_TEXT_HOSTNAME + " \\ Z" , domain ):
144+ if DOT_ATOM_TEXT_HOSTNAME .match (domain ):
145145 ascii_domain = domain
146146 else :
147147 # 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
170170
171171 # Check the syntax of the string returned by idna.encode.
172172 # It should never fail.
173- m = re .match (DOT_ATOM_TEXT_HOSTNAME + " \\ Z" , ascii_domain )
173+ m = DOT_ATOM_TEXT_HOSTNAME .match (ascii_domain )
174174 if not m :
175175 raise EmailSyntaxError ("The email address contains invalid characters after the @-sign after IDNA encoding." )
176176
@@ -198,7 +198,7 @@ def validate_email_domain_part(domain, test_environment=False, globally_delivera
198198 raise EmailSyntaxError ("The part after the @-sign is not valid. It should have a period." )
199199
200200 # 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 ):
202202 raise EmailSyntaxError ("The part after the @-sign is not valid. It is not within a valid top-level domain." )
203203
204204 # Check special-use and reserved domain names.
0 commit comments