human
Solve the following python programming problem given the following code:
@cachedmethod
def asciifyUrl(url, forceQuote=False):
assistant
#Here is the Python code you requested.

    """Attempts to make a unicode URL usuable with ``urllib/urllib2``.
    More specifically, it attempts to convert the unicode object ``url``,
    which is meant to represent a IRI, to an unicode object that,
    containing only ASCII characters, is a valid URI. This involves:
    * IDNA/Puny-encoding the domain name.
    * UTF8-quoting the path and querystring parts.
    See also RFC 3987.
    Reference: http://blog.elsdoerfer.name/2008/12/12/opening-iris-in-python/
    >>> asciifyUrl(u\http://www.\u0161u\u0107uraj.com\)
    u\http://www.xn--uuraj-gxa24d.com\
    """
    parts = urlparse.urlsplit(url)
    if ((not parts.scheme) or (not parts.netloc)):
        return url
    if all(((char in string.printable) for char in url)):
        return url
    try:
        hostname = parts.hostname.encode('idna')
    except LookupError:
        hostname = parts.hostname.encode(UNICODE_ENCODING)
    def quote(s, safe):
        s = (s or '')
        if ((s.encode('ascii', 'replace') != s) or forceQuote):
            return urllib.quote(s.encode(UNICODE_ENCODING), safe=safe)
        return s
    username = quote(parts.username, '')
    password = quote(parts.password, safe='')
    path = quote(parts.path, safe='/')
    query = quote(parts.query, safe='&=')
    netloc = hostname
    if (username or password):
        netloc = ('@' + netloc)
        if password:
            netloc = ((':' + password) + netloc)
        netloc = (username + netloc)
    try:
        port = parts.port
    except:
        port = None
    if port:
        netloc += (':' + str(port))
    return urlparse.urlunsplit([parts.scheme, netloc, path, query, parts.fragment])