idna
idna copied to clipboard
Function to check if a string is an idna domain
It would be great if there a was a function in the library that would return true/false if the supplied string/bytes is an idn domain or not.
~How about this?~
def is_idna(s: str):
return idna.encode(s).startswith(b'xn--')
~It works with both unicode and punycode formats.~ Do not use, will throw exception on unsuccessful encode().
I'm not sure if the above function would necessarily fit the bill, not all domains prefixed with xn--
are valid IDNs, only those that have a valid Punycode conversion based on the remainder of the string would be. @ITJamie can you confirm your request is to check for that it is a algorithmically valid IDN, or just has the potential to be a valid IDN based on further processing?
Also the above looks like it would throw an exception for an unsuccessful encode(), rather than returning False.
As there has been no further input from the requester in many months, closing this request.