Closed elliotwutingfeng closed 9 months ago
I'm reluctant to merge this PR. Only one person has asked for this functionality and hasn't even confirmed in their issue that this is even what they are looking for. Given it is only subtly different from using encode() for the same purpose I am not sure it is worth adding this new function.
Alright, I think this should be closed for now and left for future reference.
Closes #149.
Assumption: Does idna.encode() always throw an exception for strings that contain invalid punycode and/or unconvertible unicode (such as emojis)?
is_idna(s) returns True if a given string
s
can be encoded by idna.encode() without error, and at least one of its encoded labels begins withb"xn--"
.A more efficient implementation would be to reuse portions of idna.encode() so that the per-label
b"xn--"
checks can be done before doings = b'.'.join(result)
for the final valid_string_length() check.