def split_path(path, abs_path=True):
    """Splits a URI-encoded path into path segments

    path
        A character string containing the path component of a URI. If
        path is None we treat as for an empty string.

    abs_path
        A flag (defaults to True) indicating whether or not the
        path is relative or absolute.  This flag only affects
        the handling of the empty path.  An empty absolute path
        is treated as if it were '/' and returns a list containing
        a single empty path segment whereas an empty relative
        path returns a list with no path segments, in other words,
        an empty list.

    The return result is always a list of character strings split from
    *path*.  It will only end in an empty path segment if the path ends
    with a slash."""
    if path:
        if abs_path:
            if ord(path[0]) != 0x2F:
                raise ValueError("Abs path must be empty or start with /")
            return path.split("/")[1:]
        else:
            return path.split("/")
    elif not abs_path:
        # relative paths always have an empty segment
        return ['']
    else:
        return []