code: def _validate_normalize_engine(
      engine: Optional[Literal["vl-convert", "altair_saver"]],
      format: Literal["png", "svg", "pdf", "vega"],
  ) -> str:
      """Helper to validate and normalize the user-provided engine
  
      engine : {None, 'vl-convert', 'altair_saver'}
          the user-provided engine string
      format : string {'png', 'svg', 'pdf', 'vega'}
          the format of the mimebundle to be returned
      """
      # Try to import vl_convert
      try:
          vlc = import_vl_convert()
      except ImportError:
          vlc = None
  
      # Try to import altair_saver
      try:
          import altair_saver
      except ImportError:
          altair_saver = None
  
      # Normalize engine string by lower casing and removing underscores and hyphens
      normalized_engine = (
          None
          if engine is None
          else engine.lower().replace("-", "").replace("_", "")
      )
  
      # Validate or infer default value of normalized_engine
      if normalized_engine == "vlconvert":
          if vlc is None:
              raise ValueError(
                  "The 'vl-convert' conversion engine requires the vl-convert-python package"
              )
      elif normalized_engine == "altairsaver":
          if altair_saver is None:
              raise ValueError(
                  "The 'altair_saver' conversion engine requires the altair_saver package"
              )
      elif normalized_engine is None:
          if vlc is not None:
              normalized_engine = "vlconvert"
          elif altair_saver is not None:
              normalized_engine = "altairsaver"
          else:
              raise ValueError(
                  "Saving charts in {fmt!r} format requires the vl-convert-python or altair_saver package: "
                  "see http://github.com/altair-viz/altair_saver/".format(
                      fmt=format
                  )
              )
      else:
          raise ValueError(
              "Invalid conversion engine {engine!r}. Expected one of {valid!r}".format(
                  engine=engine, valid=("vl-convert", "altair_saver")
              )
          )
      return normalized_engine
  
file_path: altair/altair/utils/mimebundle.py
imports: from typing import Literal, Optional, Union, cast, Tuple
  from .deprecation import AltairDeprecationWarning
  from .html import spec_to_html
  from ._importers import import_vl_convert, vl_version_for_vl_convert
  import struct
  import warnings
label_desc: Use image node_id 3 for calling a global function with example usage: _validate_normalize_engine(engine, format) and returns: normalized_engine