code: def _encode(string, codec):
      if codec == UNKNOWN8BIT:
          return string.encode("ascii", "surrogateescape")
      else:
          return string.encode(codec)
  
file_path: cpython/Lib/email/charset.py
imports: from functools import partial
  import email.base64mime
  import email.quoprimime
  from email import errors
  from email.encoders import encode_7or8bit
label_desc: Use image node_id 4 for calling a global function with example usage: _encode(string, codec) and returns: string, string