@@ -466,8 +466,9 @@ def check_label(label: str | bytes | bytearray) -> None:
466466 if len (label ) == 0 :
467467 raise IDNAError ("Empty Label" , code = "empty_label" )
468468
469- # Reject on domain length rather than label length so support some UTS 46
470- # use cases, still reducing processing of label contextual rules
469+ # Check against the domain length rather than the label length to
470+ # support some UTS #46 use cases, while still bounding the work done
471+ # by the label contextual rules below.
471472 if not valid_string_length (label , trailing_dot = True ):
472473 raise IDNAError ("Label too long" , code = "label_too_long" )
473474
@@ -662,31 +663,27 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
662663 if len (domain ) > _max_input_length :
663664 raise IDNAError ("Domain too long" , code = "input_too_long" )
664665 if domain .isascii ():
665- # The only ASCII mapping in UTS #46 is upper- to lowercase; every
666- # other ASCII codepoint has status V (tests pin this against the
667- # table). ASCII is invariant under NFC, so this is the whole job.
666+ # The only ASCII mapping in UTS #46 is upper- to lowercase, and
667+ # ASCII is invariant under NFC, so lowercasing is the whole job.
668668 result = domain .lower ()
669669 if std3_rules :
670670 _check_std3 (result , domain , 0 )
671671 return result
672672
673673 from .uts46data import uts46_replacements , uts46_starts , uts46_statuses
674674
675- # Characters that pass through unchanged are not copied one at a time:
676- # ``start`` marks the beginning of the current run of unchanged input,
677- # and a run is only sliced out when a character has to be replaced or
678- # dropped. For the common case where nothing changes no copy is made.
679- # The STD3 check is applied to each piece of output as it is produced,
680- # so that a violation is reported at its position in the input.
675+ # ``start`` marks the run of unchanged input not yet copied; a run is
676+ # only sliced out when a character must be replaced or dropped, so the
677+ # common no-change case makes no copy. STD3 is checked per output piece
678+ # to report a violation at its input position.
681679 output : list [str ] = []
682680 start = 0
683681 for pos , char in enumerate (domain ):
684682 code_point = ord (char )
685683 i = code_point if code_point < 256 else bisect .bisect_right (uts46_starts , code_point ) - 1
686684 status = uts46_statuses [i ]
687- # UTS #46 §4: V is always valid, D is deviation (kept: transitional
688- # processing, which mapped it, is deprecated), M is mapped, I is
689- # ignored, anything else is disallowed.
685+ # UTS #46 §4: V valid, D deviation (kept), M mapped, I ignored,
686+ # anything else disallowed.
690687 if status == _STATUS_VALID :
691688 continue
692689 if status == _STATUS_MAPPED :
@@ -773,8 +770,6 @@ def encode(
773770 if uts46 :
774771 s = uts46_remap (s , std3_rules )
775772
776- # Reject inputs that exceed the maximum DNS domain length up-front
777- # to avoid expensive computation on long inputs.
778773 if not valid_string_length (s , trailing_dot = True ):
779774 raise IDNAError ("Domain too long" , code = "domain_too_long" )
780775
@@ -840,8 +835,6 @@ def decode(
840835 raise IDNAError ("Domain too long" , code = "input_too_long" )
841836 if uts46 :
842837 s = uts46_remap (s , std3_rules , False )
843- # Reject inputs that exceed the maximum DNS domain length up-front
844- # to avoid expensive computation on long inputs.
845838 if not valid_string_length (s , trailing_dot = True ):
846839 raise IDNAError ("Domain too long" , code = "domain_too_long" )
847840 trailing_dot = False
0 commit comments