def _normalizePath(path):
    """Normalize a path by resolving '.' and '..' path elements."""
    if path == u'/':
        return path
    new_segments = []
    prefix = u''
    if path.startswith('/'):
        prefix = u'/'
        path = path[1:]
    for segment in path.split(u'/'):
        if segment == u'.':
            continue
        if segment == u'..':
            new_segments.pop()
            continue
        if not segment:
            raise ValueError('path must not contain empty segments: %s' % path)
        new_segments.append(segment)
    return prefix + u'/'.join(new_segments)
