code: def stat_name_default_handler(
      stat_name: str,
      max_length: int = 250,
      allowed_chars: Iterable[str] = ALLOWED_CHARACTERS,
  ) -> str:
      """
      Validate the metric stat name.
  
      Apply changes when necessary and return the transformed stat name.
      """
      if not isinstance(stat_name, str):
          raise InvalidStatsNameException(
              "The stat_name has to be a string"
          )
      if len(stat_name) > max_length:
          raise InvalidStatsNameException(
              f"The stat_name ({stat_name}) has to be less than {max_length} characters."
          )
      if any(c not in allowed_chars for c in stat_name):
          raise InvalidStatsNameException(
              f"The stat name ({stat_name}) has to be composed of ASCII "
              f"alphabets, numbers, or the underscore, dot, or dash characters."
          )
      return stat_name
  
imports: from __future__ import annotations
  import abc
  import logging
  import string
  import warnings
  from functools import partial, wraps
  from typing import Callable, Iterable, Pattern, cast
  import re2
  from airflow.configuration import conf
  from airflow.exceptions import InvalidStatsNameException, RemovedInAirflow3Warning
label_desc: Use image node_id 4 for calling a global function with example usage: stat_name_default_handler(stat_name, max_length, allowed_chars) and returns: stat_name