code: def make_compat_str(in_str):
      
      assert isinstance(in_str, (bytes, str, unicode))
      if not in_str:
          return unicode()
  
      # Chardet in Py2 works on str + bytes objects
      if IS_PY2 and isinstance(in_str, unicode):
          return in_str
  
      # Chardet in Py3 works on bytes objects
      if not IS_PY2 and not isinstance(in_str, bytes):
          return in_str
  
      # Detect the encoding now
      enc = chardet.detect(in_str)
  
      # Decode the object into a unicode object
      out_str = in_str.decode(enc['encoding'])
  
      # Cleanup: Sometimes UTF-16 strings include the BOM
      if enc['encoding'] == "UTF-16BE":
          # Remove byte order marks (BOM)
          if out_str.startswith('\ufeff'):
              out_str = out_str[1:]
  
      # Return the decoded string
      return out_str
docs: Tries to guess encoding of [str/bytes] and decode it into
      an unicode object.