def ascii_escaped(val):
    'If val is pure ascii, returns it as a str().  Otherwise, escapes\n    bytes objects into a sequence of escaped bytes:\n\n    b\'Ã´ÅÖ\' -> \'\\xc3\\xb4\\xc5\\xd6\'\n\n    and escapes unicode objects into a sequence of escaped unicode\n    ids, e.g.:\n\n    \'4\\nV\\U00043efa\\x0eMXWB\\x1e\\u3028\\u15fd\\xcd\\U0007d944\'\n\n    note:\n       the obvious "v.decode(\'unicode-escape\')" will return\n       valid utf-8 unicode if it finds them in bytes, but we\n       want to return escaped bytes for any byte, even if they match\n       a utf-8 string.\n\n    '
    if isinstance(val, bytes):
        ret = _bytes_to_ascii(val)
    else:
        ret = val.encode('unicode_escape').decode('ascii')
    return _translate_non_printable(ret)
If val is pure ascii, returns it as a str().  Otherwise, escapes
bytes objects into a sequence of escaped bytes:

b'Ã´ÅÖ' -> '\xc3\xb4\xc5\xd6'

and escapes unicode objects into a sequence of escaped unicode
ids, e.g.:

'4\nV\U00043efa\x0eMXWB\x1e\u3028\u15fd\xcd\U0007d944'

note:
   the obvious "v.decode('unicode-escape')" will return
   valid utf-8 unicode if it finds them in bytes, but we
   want to return escaped bytes for any byte, even if they match
   a utf-8 string.
def ascii_escaped(val):
    'If val is pure ascii, returns it as a str().  Otherwise, escapes\n    bytes objects into a sequence of escaped bytes:\n\n    b\'Ã´ÅÖ\' -> \'\\xc3\\xb4\\xc5\\xd6\'\n\n    and escapes unicode objects into a sequence of escaped unicode\n    ids, e.g.:\n\n    \'4\\nV\\U00043efa\\x0eMXWB\\x1e\\u3028\\u15fd\\xcd\\U0007d944\'\n\n    note:\n       the obvious "v.decode(\'unicode-escape\')" will return\n       valid utf-8 unicode if it finds them in bytes, but we\n       want to return escaped bytes for any byte, even if they match\n       a utf-8 string.\n\n    '
    if isinstance(val, bytes):
        ret = _bytes_to_ascii(val)
    else:
        ret = val.encode('unicode_escape').decode('ascii')
    return _translate_non_printable(ret)