from django.utils.encoding import force_str
from django.utils.functional import keep_lazy
from django.utils.safestring import SafeText, mark_safe

_json_escapes = {
    ord('>'): '\\u003E',
    ord('<'): '\\u003C',
    ord('&'): '\\u0026',
}

_json_escapes_attr = {
    ord('>'): '\\u003E',
    ord('<'): '\\u003C',
    ord('&'): '\\u0026',
    ord('"'): '&#34;',
    ord("'"): '&#39;',
    ord("="): '&#61;',
}


@keep_lazy(str, SafeText)
def escapejson(value):
    """Hex encodes characters for use in a application/json type script."""
    return mark_safe(force_str(value).translate(_json_escapes))


@keep_lazy(str, SafeText)
def escapejson_attr(value):
    """Hex encodes characters for use in a html attributw script."""
    return mark_safe(force_str(value).translate(_json_escapes_attr))

[((21, 1, 21, 25), 'django.utils.functional.keep_lazy', 'keep_lazy', ({(21, 11, 21, 14): 'str', (21, 16, 21, 24): 'SafeText'}, {}), '(str, SafeText)', False, 'from django.utils.functional import keep_lazy\n'), ((27, 1, 27, 25), 'django.utils.functional.keep_lazy', 'keep_lazy', ({(27, 11, 27, 14): 'str', (27, 16, 27, 24): 'SafeText'}, {}), '(str, SafeText)', False, 'from django.utils.functional import keep_lazy\n'), ((24, 21, 24, 37), 'django.utils.encoding.force_str', 'force_str', ({(24, 31, 24, 36): 'value'}, {}), '(value)', False, 'from django.utils.encoding import force_str\n'), ((30, 21, 30, 37), 'django.utils.encoding.force_str', 'force_str', ({(30, 31, 30, 36): 'value'}, {}), '(value)', False, 'from django.utils.encoding import force_str\n')]