Join a base URL and a (possiby relative) URL.

    base - base url
    url - a (possibly relative) URL to join to the base URL

    Returns the result as an absolute URL.

def urljoin(base, url):
    """Join a base URL and a (possiby relative) URL.

    base - base url
    url - a (possibly relative) URL to join to the base URL

    Returns the result as an absolute URL.

    """
    import posixpath
    bscheme, bauthority, bpath, bquery, bfragment = urisplit(base)
    uscheme, uauthority, upath, uquery, ufragment = urisplit(url)
    if uscheme is not None and bscheme != uscheme:
        return url
    if uauthority is not None:
        bauthority, bpath, bquery, bfragment = \
            uauthority, upath, uquery, ufragment
    elif upath != '':
        bpath = posixpath.normpath(_pathjoin(_dirname(bpath), upath))
        bquery, bfragment = uquery, ufragment
    elif uquery is not None:
        bquery, bfragment = uquery, ufragment
    elif ufragment is not None:
        bfragment = ufragment
    return uriunsplit((bscheme, bauthority, bpath, bquery, bfragment))