import six
import codecs


def escape_utf_8_chars(input_text):
    """
    Escapes characters like "\xe4" with "\u00e4".
    Only necessary to support Python 2.7+.
    """
    ascii_text = six.binary_type()
    for c in input_text:
        encoded = c.encode("utf-8")
        if len(encoded) != 1:
            for b in bytearray(encoded):
                ascii_text += six.b(r"\\u00" + "%x" % b)
        else:
            ascii_text += six.b(c)
    return codecs.decode(ascii_text, "utf-8")