Skip to content

Commit b32933d

Browse files
committed
Improve some code comments
1 parent 5d88189 commit b32933d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

email_validator/syntax.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,17 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
322322

323323
# Perform UTS-46 normalization, which includes casefolding, NFC normalization,
324324
# and converting all label separators (the period/full stop, fullwidth full stop,
325-
# ideographic full stop, and halfwidth ideographic full stop) to basic periods.
325+
# ideographic full stop, and halfwidth ideographic full stop) to regular dots.
326326
# It will also raise an exception if there is an invalid character in the input,
327-
# such as "⒈" which is invalid because it would expand to include a period.
327+
# such as "⒈" which is invalid because it would expand to include a dot.
328+
# Since several characters are normalized to a dot, this has to come before
329+
# checks related to dots, like check_dot_atom which comes next.
328330
try:
329331
domain = idna.uts46_remap(domain, std3_rules=False, transitional=False)
330332
except idna.IDNAError as e:
331333
raise EmailSyntaxError(f"The part after the @-sign contains invalid characters ({e}).")
332334

333-
# The domain part is made up period-separated "labels." Each label must
335+
# The domain part is made up dot-separated "labels." Each label must
334336
# have at least one character and cannot start or end with dashes, which
335337
# means there are some surprising restrictions on periods and dashes.
336338
# Check that before we do IDNA encoding because the IDNA library gives
@@ -362,6 +364,8 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
362364
# For ASCII-only domains, the transformation does nothing and is safe to
363365
# apply. However, to ensure we don't rely on the idna library for basic
364366
# syntax checks, we don't use it if it's not needed.
367+
#
368+
# uts46 is off here because it is handled above.
365369
try:
366370
ascii_domain = idna.encode(domain, uts46=False).decode("ascii")
367371
except idna.IDNAError as e:
@@ -371,6 +375,9 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
371375
# one the user supplied. Also I'm not sure if the length check applies
372376
# to the internationalized form, the IDNA ASCII form, or even both!
373377
raise EmailSyntaxError("The email address is too long after the @-sign.")
378+
379+
# Other errors seem to not be possible because the call to idna.uts46_remap
380+
# would have already raised them.
374381
raise EmailSyntaxError(f"The part after the @-sign contains invalid characters ({e}).")
375382

376383
# Check the syntax of the string returned by idna.encode.

0 commit comments

Comments
 (0)