def safe_re_encode(s, encoding_to, errors="<STR_LIT>"):
<EOL>if not encoding_to:<EOL><INDENT>encoding_to = "<STR_LIT>"<EOL><DEDENT>if compat.is_bytes(s):<EOL><INDENT>s = s.decode(encoding_to, errors=errors).encode(encoding_to)<EOL><DEDENT>else:<EOL><INDENT>s = s.encode(encoding_to, errors=errors).decode(encoding_to)<EOL><DEDENT>return s<EOL>
Re-encode str or binary so that is compatible with a given encoding (replacing
    unsupported chars).

    We use ASCII as default, which gives us some output that contains \x99 and \u9999
    for every character > 127, for easier debugging.
    (e.g. if we don't know the encoding, see #87, #96)