def abspath(newpath, curpath):
    """Return the absolute path to the given 'newpath'.

    The current directory string must be given by 'curpath' as an absolute
    path.
    """
    assert newpath
    assert curpath
    assert curpath.startswith('/')
    subdirs = newpath.split('/')
    if not subdirs[0] or curpath == '/':
        dirs = ['']
    else:
        dirs = curpath.split('/')
    for s in subdirs:
        if not s or s == '.':
            pass
        elif s == '..':
            dirs.pop()
            if not dirs:
                raise ValueError("Too many '..' in path '{}'".format(newpath))
        else:
            dirs.append(s)
    if len(dirs) == 1:
        return '/'
    return '/'.join(dirs)
