To encode/decode a domain using “Internationalized Domain Names”

$ python
>>> x = u'qé'
>>> x.encode('idna')
>>> x.encode('idna').decode('idna')
>>> x == x.encode('idna').decode('idna')

To prevent non-international domain names containing hyphens from being accidentally interpreted as Punycode, international domain name Punycode sequences have a so-called ASCII Compatible Encoding (ACE) prefix, “xn–”, prepended.[2] Thus the domain name “bücher.tld” would be represented in ASCII as “xn–bcher-kva.tld”.