def _urljoin(left, right):
    """Join two URLs.

    Takes URLs specified by left and right and joins them into a
    single URL.  If right is an absolute URL, it is returned directly.
    This differs from urlparse.urljoin() in that the latter always
    chops off the left-most component of left unless it is trailed by
    '/', which is not the behavior we want.
    """

    # Handle the tricky case of right being a full URL
    tmp = urlparse.urlparse(right)
    if tmp.scheme or tmp.netloc:
        # Go ahead and use urlparse.urljoin()
        return urlparse.urljoin(left, right)

    # Check for slashes
    joincond = (left[-1:], right[:1])
    if joincond == ('/', '/'):
        # Too many, preserve only one
        return left + right[1:]
    elif '/' in joincond:
        # Just one; great!
        return left + right
    else:
        # Not enough; add one
        return left + '/' + right
Join two URLs.

    Takes URLs specified by left and right and joins them into a
    single URL.  If right is an absolute URL, it is returned directly.
    This differs from urlparse.urljoin() in that the latter always
    chops off the left-most component of left unless it is trailed by
    '/', which is not the behavior we want.