docs: def py_encode_basestring_ascii(s, _PY3=PY3):
      """Return an ASCII-only JSON representation of a Python string
  
      """
      if _PY3:
          if isinstance(s, binary_type):
              s = s.decode('utf-8')
      else:
          if isinstance(s, str) and HAS_UTF8.search(s) is not None:
              s = s.decode('utf-8')
      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)) + '"'