class_docstr: A base class providing the backwards-compatible spawn API for Pexpect.
  
  This should not be instantiated directly: use :class:`pexpect.spawn` or
  :class:`pexpect.fdpexpect.fdspawn`.
code: def _coerce_expect_re(self, r):
      p = r.pattern
      if self.encoding is None and not isinstance(p, bytes):
          return re.compile(p.encode("utf-8"))
      # And vice-versa
      elif self.encoding is not None and isinstance(p, bytes):
          return re.compile(p.decode("utf-8"))
      return r
  
imports: from io import StringIO, BytesIO
  import codecs
  import os
  import sys
  import re
  import errno
  from .exceptions import ExceptionPexpect, EOF, TIMEOUT
  from .expect import Expecter, searcher_string, searcher_re
label_desc: Use image node_id 4 for calling the SpawnBase obj's underlying member method code with example usage: obj._coerce_expect_re(r) and returns: r, re, re