#NEWLINE# def normpath( path ) : #NEWLINE# #INDENT# 'Normalize path, eliminating double slashes, etc.' #NEWLINE# if ( path == '' ) : #NEWLINE# #INDENT# return '.' #NEWLINE# #UNINDENT# initial_slashes = path . startswith ( '/' ) #NEWLINE# if ( initial_slashes and path . startswith ( '//' ) and ( not path . startswith ( '///' ) ) ) : #NEWLINE# #INDENT# initial_slashes = 2 #NEWLINE# #UNINDENT# comps = path . split ( '/' ) #NEWLINE# new_comps = [ ] #NEWLINE# for comp in comps : #NEWLINE# #INDENT# if ( comp in ( '' , '.' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( ( comp != '..' ) or ( ( not initial_slashes ) and ( not new_comps ) ) or ( new_comps and ( new_comps [ ( - 1 ) ] == '..' ) ) ) : #NEWLINE# #INDENT# new_comps . append ( comp ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if new_comps : #NEWLINE# #INDENT# new_comps . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# comps = new_comps #NEWLINE# path = '/' . join ( comps ) #NEWLINE# if initial_slashes : #NEWLINE# #INDENT# path = ( ( '/' * initial_slashes ) + path ) #NEWLINE# #UNINDENT# return ( path or '.' )