Skip to content

Commit

Permalink
Format with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
kjd committed Sep 14, 2024
1 parent 580ece9 commit 762216b
Showing 1 changed file with 46 additions and 11 deletions.
57 changes: 46 additions & 11 deletions idna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,46 @@
_virama_combining_class = 9
_alabel_prefix = b"xn--"
_unicode_dots_re = re.compile("[\u002e\u3002\uff0e\uff61]")
_ldh = (48,49,50,51,52,53,54,55,56,57,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,
111,112,113,114,115,116,117,118,119,120,121,122)
_ldh = (
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
95,
97,
98,
99,
100,
101,
102,
103,
104,
105,
106,
107,
108,
109,
110,
111,
112,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
)


class IDNAError(UnicodeError):
"""Base exception for all IDNA-encoding related problems"""
Expand Down Expand Up @@ -342,19 +380,16 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
uts46row = uts46data[code_point if code_point < 256 else bisect.bisect_left(uts46data, (code_point, "Z")) - 1]
status = uts46row[1]
replacement: Optional[str] = None
if std3_rules and code_point <= 0x7f:
if std3_rules and code_point <= 0x7F:
if not code_point in _ldh:
raise InvalidCodepoint("Codepoint {} at position {} does not follow STD3 rules".format(_unot(code_point), pos + 1))
raise InvalidCodepoint(
"Codepoint {} at position {} does not follow STD3 rules".format(_unot(code_point), pos + 1)
)
if len(uts46row) == 3:
replacement = uts46row[2]
if (
status == "V"
or (status == "D" and not transitional)
):
if status == "V" or (status == "D" and not transitional):
output += char
elif replacement is not None and (
status == "M" or (status == "D" and transitional)
):
elif replacement is not None and (status == "M" or (status == "D" and transitional)):
output += replacement
elif status != "I":
raise IndexError()
Expand Down

0 comments on commit 762216b

Please sign in to comment.