code: def format_field(self, value: t.Any, format_spec: str) -> str:
      if hasattr(value, "__html_format__"):
          rv = value.__html_format__(format_spec)
      elif hasattr(value, "__html__"):
          if format_spec:
              raise ValueError(
                  f"Format specifier {format_spec} given, but {type(value)} does not"
                  " define __html_format__. A class that defines __html__ must define"
                  " __html_format__ to work with format specifiers."
              )
          rv = value.__html__()
      else:
          # We need to make sure the format spec is str here as
          # otherwise the wrong callback methods are invoked.
          rv = string.Formatter.format_field(
              self, value, str(format_spec)
          )
      return str(self.escape(rv))
  
imports: import functools
  import re
  import string
  import sys
  import typing
label_desc: Use image node_id 2 for calling the EscapeFormatter obj's underlying member method code with example usage: obj.format_field(value, format_spec) and returns: str