def _url_collapse_path_split(path):
 path_parts = []
 for part in path.split('/'):
  if (part == '.'):
   path_parts.append('')
  else:
   path_parts.append(part)
 path_parts = ([part for part in path_parts[:(-1)] if part] + path_parts[(-1):])
 if path_parts:
  tail_part = path_parts.pop()
 else:
  tail_part = ''
 head_parts = []
 for part in path_parts:
  if (part == '..'):
   head_parts.pop()
  else:
   head_parts.append(part)
 if (tail_part and (tail_part == '..')):
  head_parts.pop()
  tail_part = ''
 return (('/' + '/'.join(head_parts)), tail_part)

def _url_collapse_path_split ( path ) : path_parts = [ ] for part in path . split ( '/' ) : if ( part == '.' ) : path_parts . append ( '' ) else : path_parts . append ( part ) path_parts = ( [ part for part in path_parts [ : ( - 1 ) ] if part ] + path_parts [ ( - 1 ) : ] ) if path_parts : tail_part = path_parts . pop ( ) else : tail_part = '' head_parts = [ ] for part in path_parts : if ( part == '..' ) : head_parts . pop ( ) else : head_parts . append ( part ) if ( tail_part and ( tail_part == '..' ) ) : head_parts . pop ( ) tail_part = '' return ( ( '/' + '/' . join ( head_parts ) ) , tail_part )
given a url path .