(path)
return path or dot
Normalize path, eliminating double slashes, etc.
Normalize path, eliminating double slashes, etc.
Normalize path eliminating double slashes etc .
def normpath(path):
    """Normalize path, eliminating double slashes, etc."""
    path = os.fspath(path)
    if isinstance(path, bytes):
        sep = b'/'
        empty = b''
        dot = b'.'
        dotdot = b'..'
    else:
        sep = '/'
        empty = ''
        dot = '.'
        dotdot = '..'
    if path == empty:
        return dot
    initial_slashes = path.startswith(sep)
    # POSIX allows one or two initial slashes, but treats three or more
    # as single slash.
    # (see http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13)
    if (initial_slashes and
        path.startswith(sep*2) and not path.startswith(sep*3)):
        initial_slashes = 2
    comps = path.split(sep)
    new_comps = []
    for comp in comps:
        if comp in (empty, dot):
            continue
        if (comp != dotdot or (not initial_slashes and not new_comps) or
             (new_comps and new_comps[-1] == dotdot)):
            new_comps.append(comp)
        elif new_comps:
            new_comps.pop()
    comps = new_comps
    path = sep.join(comps)
    if initial_slashes:
        path = sep*initial_slashes + path
    return path or dot
def normpath ( path ) : path = os . fspath ( path ) if isinstance ( path , bytes ) : sep = b'/' empty = b'' dot = b'.' dotdot = b'..' else : sep = '/' empty = '' dot = '.' dotdot = '..' if path == empty : return dot initial_slashes = path . startswith ( sep ) # POSIX allows one or two initial slashes, but treats three or more # as single slash. # (see http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13) if ( initial_slashes and path . startswith ( sep * 2 ) and not path . startswith ( sep * 3 ) ) : initial_slashes = 2 comps = path . split ( sep ) new_comps = [ ] for comp in comps : if comp in ( empty , dot ) : continue if ( comp != dotdot or ( not initial_slashes and not new_comps ) or ( new_comps and new_comps [ - 1 ] == dotdot ) ) : new_comps . append ( comp ) elif new_comps : new_comps . pop ( ) comps = new_comps path = sep . join ( comps ) if initial_slashes : path = sep * initial_slashes + path return path or dot