code: def ascii_escaped(val: bytes | str) -> str:
      r"""If val is pure ASCII, return it as an str, otherwise, escape
      bytes objects into a sequence of escaped bytes:
  
      b'\xc3\xb4\xc5\xd6' -> r'\xc3\xb4\xc5\xd6'
  
      and escapes unicode objects into a sequence of escaped unicode
      ids, e.g.:
  
      r'4\nV\U00043efa\x0eMXWB\x1e\u3028\u15fd\xcd\U0007d944'
  
      Note:
         The obvious "v.decode('unicode-escape')" will return
         valid UTF-8 unicode if it finds them in bytes, but we
         want to return escaped bytes for any byte, even if they match
         a UTF-8 string.
      """
      if isinstance(val, bytes):
          ret = _bytes_to_ascii(val)
      else:
          ret = val
      return ret
  
imports: from __future__ import annotations
  import dataclasses
  import enum
  import functools
  import inspect
  import os
  import sys
  from inspect import Parameter
  from inspect import signature
  from pathlib import Path
  from typing import Any
  from typing import Callable
  from typing import Generic
  from typing import NoReturn
  from typing import TYPE_CHECKING
  from typing import TypeVar
  import _pytest._py.path
label_desc: Use image node_id 12 for calling a global function with example usage: ascii_escaped(val) and returns: ret