Skip to content

Commit

Permalink
Remove outdated Python syntax using pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshData committed Oct 26, 2023
1 parent fd655c0 commit 86c761c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 0 additions & 2 deletions email_validator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Export the main method, helper methods, and the public data types.
from .exceptions_types import ValidatedEmail, EmailNotValidError, \
EmailSyntaxError, EmailUndeliverableError
Expand Down
2 changes: 1 addition & 1 deletion email_validator/exceptions_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EmailUndeliverableError(EmailNotValidError):
pass


class ValidatedEmail(object):
class ValidatedEmail:
"""The validate_email function returns objects of this type holding the normalized form of the email address
and other information."""

Expand Down
2 changes: 1 addition & 1 deletion email_validator/rfc_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# addresses to also include three specific ranges of UTF8 defined in
# RFC 3629 section 4, which appear to be the Unicode code points from
# U+0080 to U+10FFFF.
ATEXT_INTL = ATEXT + u"\u0080-\U0010FFFF"
ATEXT_INTL = ATEXT + "\u0080-\U0010FFFF"
ATEXT_INTL_RE = re.compile('[.' + ATEXT_INTL + ']') # ATEXT_INTL plus dots
DOT_ATOM_TEXT_INTL = re.compile('[' + ATEXT_INTL + ']+(?:\\.[' + ATEXT_INTL + r']+)*\Z')

Expand Down
28 changes: 14 additions & 14 deletions email_validator/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
# Check for invalid characters against the non-internationalized
# permitted character set.
# (RFC 5322 3.2.3)
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in local
if not ATEXT_RE.match(c)
)
}
if bad_chars:
raise EmailSyntaxError("Internationalized characters before the @-sign are not supported: " + ", ".join(sorted(bad_chars)) + ".")

Expand All @@ -148,20 +148,20 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
# (RFC 5321 4.1.2. RFC 5322 lists additional permitted *obsolete*
# characters which are *not* allowed here. RFC 6531 section 3.3
# extends the range to UTF8 strings.)
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in local
if not QTEXT_INTL.match(c)
)
}
if bad_chars:
raise EmailSyntaxError("The email address contains invalid characters in quotes before the @-sign: " + ", ".join(sorted(bad_chars)) + ".")

# See if any characters are outside of the ASCII range.
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in local
if not (32 <= ord(c) <= 126)
)
}
if bad_chars:
requires_smtputf8 = True

Expand Down Expand Up @@ -213,11 +213,11 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp

# Check for invalid characters.
# (RFC 5322 3.2.3, plus RFC 6531 3.3)
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in local
if not ATEXT_INTL_RE.match(c)
)
}
if bad_chars:
raise EmailSyntaxError("The email address contains invalid characters before the @-sign: " + ", ".join(sorted(bad_chars)) + ".")

Expand Down Expand Up @@ -306,11 +306,11 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera

# Check for invalid characters before normalization.
# (RFC 952 plus RFC 6531 section 3.3 for internationalized addresses)
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in domain
if not ATEXT_HOSTNAME_INTL.match(c)
)
}
if bad_chars:
raise EmailSyntaxError("The part after the @-sign contains invalid characters: " + ", ".join(sorted(bad_chars)) + ".")

Expand Down Expand Up @@ -437,11 +437,11 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera

# Check for invalid characters after normalization. These
# should never arise. See the similar checks above.
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in domain
if not ATEXT_HOSTNAME_INTL.match(c)
)
}
if bad_chars:
raise EmailSyntaxError("The part after the @-sign contains invalid characters: " + ", ".join(sorted(bad_chars)) + ".")
check_unsafe_chars(domain)
Expand Down Expand Up @@ -544,11 +544,11 @@ def validate_email_domain_literal(domain_literal):

# Check for permitted ASCII characters. This actually doesn't matter
# since there will be an exception after anyway.
bad_chars = set(
bad_chars = {
safe_character_display(c)
for c in domain_literal
if not DOMAIN_LITERAL_CHARS.match(c)
)
}
if bad_chars:
raise EmailSyntaxError("The part after the @-sign contains invalid characters in brackets: " + ", ".join(sorted(bad_chars)) + ".")

Expand Down

0 comments on commit 86c761c

Please sign in to comment.