code: def py_encode_basestring_ascii(s, _PY3=PY3):
      """Return an ASCII-only JSON representation of a Python string"""
      if _PY3:
          if isinstance(s, bytes):
              s = str(s, "utf-8")
          elif type(s) is not str:
              # convert an str subclass instance to exact str
              # raise a TypeError otherwise
              s = str.__str__(s)
      else:
          if isinstance(s, str) and HAS_UTF8.search(s) is not None:
              s = unicode(s, "utf-8")
          elif type(s) not in (str, unicode):
              # convert an str subclass instance to exact str
              # convert a unicode subclass instance to exact unicode
              # raise a TypeError otherwise
              if isinstance(s, str):
                  s = str.__str__(s)
              else:
                  s = unicode.__getnewargs__(s)[0]
  
      def replace(match):
          s = match.group(0)
          try:
              return ESCAPE_DCT[s]
          except KeyError:
              n = ord(s)
              if n < 0x10000:
                  # return '\\u{0:04x}'.format(n)
                  return "\\u%04x" % (n,)
              else:
                  # surrogate pair
                  n -= 0x10000
                  s1 = 0xD800 | ((n >> 10) & 0x3FF)
                  s2 = 0xDC00 | (n & 0x3FF)
                  # return '\\u{0:04x}\\u{1:04x}'.format(s1, s2)
                  return "\\u%04x\\u%04x" % (s1, s2)
  
      return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
  
imports: from __future__ import absolute_import
  import re
  from operator import itemgetter
  import decimal
  from .compat import unichr, binary_type, text_type, string_types, integer_types, PY3
  from .decoder import PosInf
  from .raw_json import RawJSON
label_desc: Use image node_id 3 for calling a global function with example usage: py_encode_basestring_ascii(s, _PY3) and returns: unknown, ESCAPE_DCT, unknown, unknown