'Encodes URL so that IDN domains are punycode-escaped. Has no
effect on plain old ASCII domain names.'

def idnEncodedUrl(self, url):

    p = urlparse.urlparse(url)
    netloc = ((isinstance(p.netloc, unicode) and p.netloc) or p.netloc.decode('utf-8'))
    newNetloc = netloc.encode('idna')
    parts = list(p)
    parts[1] = newNetloc
    return urlparse.urlunparse(parts)
