def url_join(url):
    """Join a URLSplitResult class into a full URL. url_join(url_split(url)) returns _url_, with
       (valid) trailing slashes."""
    constructed_url = []
    if url.scheme:
        constructed_url.append(url.scheme + "://")
    constructed_url.append(url.username)
    if url.password:
        constructed_url.append(":" + url.password)
    if url.username or url.password:
        constructed_url.append("@")
    constructed_url.append(url.hostname)
    if url.port:
        constructed_url.append(":%s" % url.port)
    constructed_url.append(url.path)
    # If we have a file part and there is a hostname, make sure the path ends with a slash.
    if url.file and url.hostname and not url.path.endswith("/"):
        constructed_url.append("/")
    constructed_url.append(url.file)
    if url.params:
        constructed_url.append(";" + url.params)
    if url.query:
        constructed_url.append("?" + url.query)
    if url.anchor:
        constructed_url.append("#" + url.anchor)

    return "".join(constructed_url)