def idna_encode(string):
    """Encode a string as ASCII using IDNA so that it is a valid part of a URI

    See RFC3490.

    :param string: str
    :returns: ASCII string
    """
    return string.encode('idna').decode('ascii')