def NormalizePath(path, sep='/'):
 if (not path):
  return sep
 path = SmartUnicode(path)
 path_list = path.split(sep)
 if (path_list[0] in ['.', '..', '']):
  path_list.pop(0)
 i = 0
 while True:
  list_len = len(path_list)
  for i in range(i, len(path_list)):
   if ((path_list[i] == '.') or (not path_list[i])):
    path_list.pop(i)
    break
   elif (path_list[i] == '..'):
    path_list.pop(i)
    if (((i == 1) and path_list[0]) or (i > 1)):
     i -= 1
     path_list.pop(i)
    break
  if (len(path_list) == list_len):
   return (sep + sep.join(path_list))

def NormalizePath ( path , sep = '/' ) : if ( not path ) : return sep path = SmartUnicode ( path ) path_list = path . split ( sep ) if ( path_list [ 0 ] in [ '.' , '..' , '' ] ) : path_list . pop ( 0 ) i = 0 while True : list_len = len ( path_list ) for i in range ( i , len ( path_list ) ) : if ( ( path_list [ i ] == '.' ) or ( not path_list [ i ] ) ) : path_list . pop ( i ) break elif ( path_list [ i ] == '..' ) : path_list . pop ( i ) if ( ( ( i == 1 ) and path_list [ 0 ] ) or ( i > 1 ) ) : i -= 1 path_list . pop ( i ) break if ( len ( path_list ) == list_len ) : return ( sep + sep . join ( path_list ) )
a sane implementation of os .