def toSegments(cwd, path):
 if path.startswith('/'):
  segs = []
 else:
  segs = cwd[:]
 for s in path.split('/'):
  if ((s == '.') or (s == '')):
   continue
  elif (s == '..'):
   if segs:
    segs.pop()
   else:
    raise InvalidPath(cwd, path)
  elif (('\x00' in s) or ('/' in s)):
   raise InvalidPath(cwd, path)
  else:
   segs.append(s)
 return segs

def toSegments ( cwd , path ) : if path . startswith ( '/' ) : segs = [ ] else : segs = cwd [ : ] for s in path . split ( '/' ) : if ( ( s == '.' ) or ( s == '' ) ) : continue elif ( s == '..' ) : if segs : segs . pop ( ) else : raise InvalidPath ( cwd , path ) elif ( ( '\x00' in s ) or ( '/' in s ) ) : raise InvalidPath ( cwd , path ) else : segs . append ( s ) return segs
normalize a path .