code: def get_format(
      outfile: pathlib.Path, *, format: typing.Optional[str]
  ) -> str:
      """Return format inferred from outfile suffix and/or given ``format``.
  
      Args:
          outfile: Path for the rendered output file.
          format: Output format for rendering (``'pdf'``, ``'png'``, ...).
  
      Returns:
          The given ``format`` falling back to the inferred format.
  
      Warns:
          graphviz.UnknownSuffixWarning: If the suffix of ``outfile``
              is empty/unknown.
          graphviz.FormatSuffixMismatchWarning: If the suffix of ``outfile``
              does not match the given ``format``.
      """
      try:
          inferred_format = infer_format(outfile)
      except ValueError:
          if format is None:
              msg = (
                  "cannot infer rendering format"
                  f" from suffix {outfile.suffix!r}"
                  f" of outfile: {os.fspath(outfile)!r}"
                  " (provide format or outfile with a suffix"
                  f" from {get_supported_suffixes()!r})"
              )
              raise exceptions.RequiredArgumentError(msg)
  
          warnings.warn(
              f"unknown outfile suffix {outfile.suffix!r}"
              f' (expected: {"." + format!r})',
              category=exceptions.UnknownSuffixWarning,
          )
          return format
      else:
          assert inferred_format is not None
          if format is not None and format.lower() != inferred_format:
              warnings.warn(
                  f"expected format {inferred_format!r} from outfile"
                  f" differs from given format: {format!r}",
                  category=exceptions.FormatSuffixMismatchWarning,
              )
              return format
  
          return inferred_format
  
file_path: graphviz/graphviz/backend/rendering.py
imports: import os
  import pathlib
  import typing
  import warnings
  from .._defaults import DEFAULT_SOURCE_EXTENSION
  from ..None import _tools
  from ..None import exceptions
  from ..None import parameters
  from .None import dot_command
  from .None import execute
label_desc: Use image node_id 1 for calling a global function with example usage: get_format(outfile) and returns: inferred_format, format, format