code: def check_mesh(mesh):
      """Validate type and content of a mesh."""
      if isinstance(mesh, str):
          return datasets.fetch_surf_fsaverage(mesh)
      if not isinstance(mesh, collections.abc.Mapping):
          raise TypeError(
              "The mesh should be a str or a dictionary, "
              f"you provided: {type(mesh).__name__}."
          )
      missing = {
          "pial_left",
          "pial_right",
          "sulc_left",
          "sulc_right",
          "infl_left",
          "infl_right",
      }.difference(mesh.keys())
      if missing:
          raise ValueError(
              f"{missing} {('are' if len(missing) > 1 else 'is')} "
              "missing from the provided mesh dictionary"
          )
      return mesh
  
imports: import collections.abc
  import json
  from warnings import warn
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from nilearn import datasets, surface
  from nilearn._utils import fill_doc
  from nilearn._utils.niimg_conversions import check_niimg_3d
  from nilearn.plotting import cm
  from nilearn.plotting.html_document import HTMLDocument
  from nilearn.plotting.js_plotting_utils import add_js_lib, colorscale, get_html_template, mesh_to_plotly, to_color_strings
label_desc: Use image node_id 4 for calling a global function with example usage: check_mesh(mesh) and returns: mesh, datasets