code: def auto_ext_from_metadata(metadata):
      """Script extension from notebook metadata"""
      auto_ext = metadata.get("language_info", {}).get("file_extension")
  
      # Sage notebooks have ".py" as the associated extension in "language_info",
      # so we change it to ".sage" in that case, see #727
      if (
          auto_ext == ".py"
          and metadata.get("kernelspec", {}).get("language") == "sage"
      ):
          auto_ext = ".sage"
  
      if auto_ext is None:
          language = metadata.get("kernelspec", {}).get(
              "language"
          ) or metadata.get("jupytext", {}).get("main_language")
          if language:
              for ext in _SCRIPT_EXTENSIONS:
                  if same_language(
                      language, _SCRIPT_EXTENSIONS[ext]["language"]
                  ):
                      auto_ext = ext
                      break
  
      if auto_ext == ".r":
          return ".R"
  
      if auto_ext == ".fs":
          return ".fsx"
  
      if auto_ext == ".resource":
          return ".robot"
  
      return auto_ext
  
imports: import os
  import re
  import warnings
  import nbformat
  import yaml
  from .cell_reader import DoublePercentScriptCellReader, HydrogenCellReader, LightScriptCellReader, MarkdownCellReader, RMarkdownCellReader, RScriptCellReader, SphinxGalleryScriptCellReader
  from .cell_to_text import BareScriptCellExporter, DoublePercentCellExporter, HydrogenCellExporter, LightScriptCellExporter, MarkdownCellExporter, RMarkdownCellExporter, RScriptCellExporter, SphinxGalleryCellExporter
  from .header import header_to_metadata_and_cell, insert_or_test_version_number
  from .languages import _COMMENT_CHARS, _SCRIPT_EXTENSIONS, same_language
  from .magics import is_magic
  from .metadata_filter import metadata_filter_as_string
  from .myst import MYST_FORMAT_NAME, is_myst_available, matches_mystnb, myst_extensions, myst_version
  from .pandoc import is_pandoc_available, pandoc_version
  from .stringparser import StringParser
  from .version import __version__
label_desc: Use image node_id 16 for calling a global function with example usage: auto_ext_from_metadata(metadata) and returns: auto_ext, str, str, str