from urllib.parse import quote, urlsplit, urlunsplit


def idna2ascii(url):
    """Converts unicode url to ascii"""
    parts = urlsplit(url)
    return urlunsplit((
        parts.scheme,
        parts.netloc.encode('idna').decode('ascii'),
        quote(parts.path),
        quote(parts.query, '='),
        quote(parts.fragment),
    ))