code: def format_file_contents(
      src_contents: str,
      *,
      fast: bool,
      mode: Mode,
      lines: Collection[Tuple[int, int]] = (),
  ) -> FileContent:
      """Reformat contents of a file and return new contents.
  
      If `fast` is False, additionally confirm that the reformatted code is
      valid by calling :func:`assert_equivalent` and :func:`assert_stable` on it.
      `mode` is passed to :func:`format_str`.
      """
      if mode.is_ipynb:
          dst_contents = format_ipynb_string(
              src_contents, fast=fast, mode=mode
          )
      else:
          dst_contents = format_str(
              src_contents, mode=mode, lines=lines
          )
      if src_contents == dst_contents:
          raise NothingChanged
  
      if not fast and not mode.is_ipynb:
          # Jupyter notebooks will already have been checked above.
          check_stability_and_equivalence(
              src_contents, dst_contents, mode=mode, lines=lines
          )
      return dst_contents
  
imports: import io
  import json
  import platform
  import re
  import sys
  import tokenize
  import traceback
  from contextlib import contextmanager
  from dataclasses import replace
  from datetime import datetime, timezone
  from enum import Enum
  from json.decoder import JSONDecodeError
  from pathlib import Path
  from typing import Any, Collection, Dict, Generator, Iterator, List, MutableMapping, Optional, Pattern, Sequence, Set, Sized, Tuple, Union
  import click
  from click.core import ParameterSource
  from mypy_extensions import mypyc_attr
  from pathspec import PathSpec
  from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
  from _black_version import version
  from black.cache import Cache
  from black.comments import normalize_fmt_off
  from black.const import DEFAULT_EXCLUDES, DEFAULT_INCLUDES, DEFAULT_LINE_LENGTH, STDIN_PLACEHOLDER
  from black.files import find_project_root, find_pyproject_toml, find_user_pyproject_toml, gen_python_files, get_gitignore, normalize_path_maybe_ignore, parse_pyproject_toml, path_is_excluded, wrap_stream_for_windows
  from black.handle_ipynb_magics import PYTHON_CELL_MAGICS, TRANSFORMED_MAGICS, jupyter_dependencies_are_installed, mask_cell, put_trailing_semicolon_back, remove_trailing_semicolon, unmask_cell
  from black.linegen import LN, LineGenerator, transform_line
  from black.lines import EmptyLineTracker, LinesBlock
  from black.mode import FUTURE_FLAG_TO_FEATURE, VERSION_TO_FEATURES, Feature
  from black.mode import Mode
  from black.mode import TargetVersion, supports_feature
  from black.nodes import STARS, is_number_token, is_simple_decorator_expression, is_string_token, syms
  from black.output import color_diff, diff, dump_to_file, err, ipynb_diff, out
  from black.parsing import InvalidInput
  from black.parsing import lib2to3_parse, parse_ast, stringify_ast
  from black.ranges import adjusted_lines, convert_unchanged_lines, parse_line_ranges
  from black.report import Changed, NothingChanged, Report
  from black.trans import iter_fexpr_spans
  from blib2to3.pgen2 import token
  from blib2to3.pytree import Leaf, Node
label_desc: Use image node_id 13 for calling a global function with example usage: format_file_contents(src_contents) and returns: dst_contents