def vfs_normpath(path):
 (slash, dot) = ((u'/', u'.') if isinstance(path, unicode) else ('/', '.'))
 if (path == ''):
  return dot
 initial_slashes = path.startswith('/')
 if (initial_slashes and path.startswith('//') and (not path.startswith('///'))):
  initial_slashes = 2
 comps = path.split('/')
 new_comps = []
 for comp in comps:
  if (comp in ('', '.')):
   continue
  if ((comp != '..') or ((not initial_slashes) and (not new_comps)) or (new_comps and (new_comps[(-1)] == '..'))):
   new_comps.append(comp)
  elif new_comps:
   new_comps.pop()
 comps = new_comps
 path = slash.join(comps)
 if initial_slashes:
  path = ((slash * initial_slashes) + path)
 return (path or dot)

def vfs_normpath ( path ) : ( slash , dot ) = ( ( u'/' , u'.' ) if isinstance ( path , unicode ) else ( '/' , '.' ) ) if ( path == '' ) : return dot initial_slashes = path . startswith ( '/' ) if ( initial_slashes and path . startswith ( '//' ) and ( not path . startswith ( '///' ) ) ) : initial_slashes = 2 comps = path . split ( '/' ) new_comps = [ ] for comp in comps : if ( comp in ( '' , '.' ) ) : continue if ( ( comp != '..' ) or ( ( not initial_slashes ) and ( not new_comps ) ) or ( new_comps and ( new_comps [ ( - 1 ) ] == '..' ) ) ) : new_comps . append ( comp ) elif new_comps : new_comps . pop ( ) comps = new_comps path = slash . join ( comps ) if initial_slashes : path = ( ( slash * initial_slashes ) + path ) return ( path or dot )
normalize path from posixpath .