code: def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
      """Translate a shell-like wildcard pattern to a compiled regular
      expression.  Return the compiled regex.  If 'is_regex' true,
      then 'pattern' is directly compiled to a regex (if it's a string)
      or just returned as-is (assumes it's a regex object).
      """
      if is_regex:
          if isinstance(pattern, str):
              return re.compile(pattern)
          else:
              return pattern
  
      # ditch start and end characters
      start, _, end = glob_to_re("_").partition("_")
  
      if pattern:
          pattern_re = glob_to_re(pattern)
          assert pattern_re.startswith(start) and pattern_re.endswith(
              end
          )
      else:
          pattern_re = ""
  
      if prefix is not None:
          prefix_re = glob_to_re(prefix)
          assert prefix_re.startswith(start) and prefix_re.endswith(end)
          prefix_re = prefix_re[len(start) : len(prefix_re) - len(end)]
          sep = os.sep
          if os.sep == "\\":
              sep = r"\\"
          pattern_re = pattern_re[
              len(start) : len(pattern_re) - len(end)
          ]
          pattern_re = r"{}\A{}{}.*{}{}".format(
              start, prefix_re, sep, pattern_re, end
          )
      else:  # no prefix -- respect anchor flag
          if anchor:
              pattern_re = r"{}\A{}".format(
                  start, pattern_re[len(start) :]
              )
  
      return re.compile(pattern_re)
  
imports: import os
  import re
  import fnmatch
  import functools
  from .util import convert_path
  from .errors import DistutilsTemplateError, DistutilsInternalError
  from ._log import log
label_desc: Use image node_id 4 for calling a global function with example usage: translate_pattern(pattern, anchor, prefix, is_regex) and returns: re, re, pattern