code: def _translate_pattern(pat: str) -> str:
      """Translate a shell-style glob pattern to a regular expression.
  
      Adapted from the fnmatch module, but enhanced so that single stars don't
      match slashes.
      """
      i, n = 0, len(pat)
      res = ""
      while i < n:
          c = pat[i]
          i += 1
          if c == "*":
              if i < n and pat[i] == "*":
                  # double star matches slashes too
                  i += 1
                  res = res + ".*"
              else:
                  # single star doesn't match slashes
                  res = res + "[^/]*"
          elif c == "?":
              # question mark doesn't match slashes too
              res = res + "[^/]"
          elif c == "[":
              j = i
              if j < n and pat[j] == "!":
                  j += 1
              if j < n and pat[j] == "]":
                  j += 1
              while j < n and pat[j] != "]":
                  j += 1
              if j >= n:
                  res = res + "\\["
              else:
                  stuff = pat[i:j].replace("\\", "\\\\")
                  i = j + 1
                  if stuff[0] == "!":
                      # negative pattern mustn't match slashes too
                      stuff = "^/" + stuff[1:]
                  elif stuff[0] == "^":
                      stuff = "\\" + stuff
                  res = f"{res}[{stuff}]"
          else:
              res += re.escape(c)
      return res + "$"
  
file_path: sphinx/sphinx/util/matching.py
imports: from __future__ import annotations
  import os.path
  import re
  from typing import TYPE_CHECKING, Callable
  from sphinx.util.osutil import canon_path, path_stabilize
label_desc: Use image node_id 1 for calling a global function with example usage: _translate_pattern(pat) and returns: unknown