code: def fetch_inventory(app: Sphinx, uri: str, inv: str) -> Inventory:
      """Fetch, parse and return an intersphinx inventory file."""
      # both *uri* (base URI of the links to generate) and *inv* (actual
      # location of the inventory file) can be local or remote URIs
      if "://" in uri:
          # case: inv URI points to remote resource; strip any existing auth
          uri = _strip_basic_auth(uri)
      try:
          if "://" in inv:
              f = _read_from_url(inv, config=app.config)
          else:
              f = open(path.join(app.srcdir, inv), "rb")  # NoQA: SIM115
      except Exception as err:
          err.args = (
              "intersphinx inventory %r not fetchable due to %s: %s",
              inv,
              err.__class__,
              str(err),
          )
          raise
      try:
          if hasattr(f, "url"):
              newinv = f.url
              if inv != newinv:
                  logger.info(
                      __("intersphinx inventory has moved: %s -> %s"),
                      inv,
                      newinv,
                  )
  
                  if uri in (
                      inv,
                      path.dirname(inv),
                      path.dirname(inv) + "/",
                  ):
                      uri = path.dirname(newinv)
          with f:
              try:
                  invdata = InventoryFile.load(f, uri, posixpath.join)
              except ValueError as exc:
                  raise ValueError(
                      "unknown or unsupported inventory version: %r"
                      % exc
                  ) from exc
      except Exception as err:
          err.args = (
              "intersphinx inventory %r not readable due to %s: %s",
              inv,
              err.__class__.__name__,
              str(err),
          )
          raise
      else:
          return invdata
  
imports: from __future__ import annotations
  import concurrent.futures
  import functools
  import posixpath
  import re
  import sys
  import time
  from os import path
  from typing import TYPE_CHECKING, cast
  from urllib.parse import urlsplit, urlunsplit
  from docutils import nodes
  from docutils.utils import relative_path
  import sphinx
  from sphinx.addnodes import pending_xref
  from sphinx.builders.html import INVENTORY_FILENAME
  from sphinx.errors import ExtensionError
  from sphinx.locale import _, __
  from sphinx.transforms.post_transforms import ReferencesResolver
  from sphinx.util import logging, requests
  from sphinx.util.docutils import CustomReSTDispatcher, SphinxRole
  from sphinx.util.inventory import InventoryFile
label_desc: Use image node_id 4 for calling a global function with example usage: fetch_inventory(app, uri, inv) and returns: invdata