def METHOD_NAME(path):
    # type: (str) -> str
    """Normalize path, eliminating double slashes, etc."""
    slash = '/'
    dot = '.'
    if path == '':
        return dot
    initial_slashes = path.startswith('/')  # type: int
    # POSIX allows one or two initial slashes, but treats three or more
    # as single slash.
    if (initial_slashes and
        path.startswith('//') and not path.startswith('///')):
        initial_slashes = 2
    comps = path.split('/')
    new_comps = []  # type: List[str]
    for comp in comps:
        if len(comp) == 0 or comp == '.':  # mycpp rewrite: comp in ('', '.')
            continue
        if (comp != '..' or (initial_slashes == 0 and len(new_comps) == 0) or
            (len(new_comps) and new_comps[-1] == '..')):
            new_comps.append(comp)
        elif len(new_comps):
            new_comps.pop()
    comps = new_comps
    path = slash.join(comps)
    if initial_slashes:
        path = slash*initial_slashes + path
    return path if len(path) else dot