code: def _url_collapse_path(path):
      """
      Given a URL path, remove extra '/'s and '.' path elements and collapse
      any '..' references and returns a collapsed path.
  
      Implements something akin to RFC-2396 5.2 step 6 to parse relative paths.
      The utility of this function is limited to is_cgi method and helps
      preventing some security attacks.
  
      Returns: The reconstituted URL, which will always start with a '/'.
  
      Raises: IndexError if too many '..' occur within the path.
  
      """
      # Query component should not be involved.
      path, _, query = path.partition("?")
      path = urllib.parse.unquote(path)
  
      # Similar to os.path.split(os.path.normpath(path)) but specific to URL
      # path semantics rather than local operating system semantics.
      path_parts = path.split("/")
      head_parts = []
      for part in path_parts[:-1]:
          if part == "..":
              head_parts.pop()  # IndexError if more '..' than prior parts
          elif part and part != ".":
              head_parts.append(part)
      if path_parts:
          tail_part = path_parts.pop()
          if tail_part:
              if tail_part == "..":
                  head_parts.pop()
                  tail_part = ""
              elif tail_part == ".":
                  tail_part = ""
      else:
          tail_part = ""
  
      if query:
          tail_part = "?".join((tail_part, query))
  
      splitpath = ("/" + "/".join(head_parts), tail_part)
      collapsed_path = "/".join(splitpath)
  
      return collapsed_path
  
imports: import copy
  import datetime
  import email.utils
  import html
  import http.client
  import io
  import itertools
  import mimetypes
  import os
  import posixpath
  import select
  import shutil
  import socket
  import socketserver
  import sys
  import time
  import urllib.parse
  from http import HTTPStatus
label_desc: Use image node_id 1 for calling a global function with example usage: _url_collapse_path(path) and returns: collapsed_path