code: def _escaped_text_from_text(text, escapes="eol"):
      r"""Return escaped version of text.
  
      "escapes" is either a mapping of chars in the source text to
          replacement text for each such char or one of a set of
          strings identifying a particular escape style:
              eol
                  replace EOL chars with '\r' and '\n', maintain the actual
                  EOLs though too
              whitespace
                  replace EOL chars as above, tabs with '\t' and spaces
                  with periods ('.')
              eol-one-line
                  replace EOL chars with '\r' and '\n'
              whitespace-one-line
                  replace EOL chars as above, tabs with '\t' and spaces
                  with periods ('.')
      """
      # TODO:
      # - Add 'c-string' style.
      # - Add _escaped_html_from_text() with a similar call sig.
      import re
  
      if isinstance(escapes, str):
          if escapes == "eol":
              escapes = {
                  "\r\n": "\\r\\n\r\n",
                  "\n": "\\n\n",
                  "\r": "\\r\r",
              }
          elif escapes == "whitespace":
              escapes = {
                  "\r\n": "\\r\\n\r\n",
                  "\n": "\\n\n",
                  "\r": "\\r\r",
                  "\t": "\\t",
                  " ": ".",
              }
          elif escapes == "eol-one-line":
              escapes = {"\n": "\\n", "\r": "\\r"}
          elif escapes == "whitespace-one-line":
              escapes = {
                  "\n": "\\n",
                  "\r": "\\r",
                  "\t": "\\t",
                  " ": ".",
              }
          else:
              raise ValueError(
                  "unknown text escape style: %r" % escapes
              )
  
      # Sort longer replacements first to allow, e.g. '\r\n' to beat '\r' and
      # '\n'.
      escapes_keys = list(escapes.keys())
      escapes_keys.sort(key=lambda a: len(a), reverse=True)
  
      def repl(match):
          val = escapes[match.group(0)]
          return val
  
      escaped = re.sub(
          "(%s)" % "|".join([re.escape(k) for k in escapes_keys]),
          repl,
          text,
      )
  
      return escaped
  
imports: import os
  import sys
  from os.path import join, dirname, abspath, exists, splitext, basename
  import re
  from glob import glob
  import unittest
  import codecs
  import difflib
  import doctest
  from json import loads
label_desc: Use image node_id 9 for calling a global function with example usage: _escaped_text_from_text(text, escapes) and returns: escaped, val