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))

[((415, 439), 'django.utils.functional.keep_lazy', 'keep_lazy', (['str', 'SafeText'], {}), '(str, SafeText)\n', (424, 439), False, 'from django.utils.functional import keep_lazy\n'), ((606, 630), 'django.utils.functional.keep_lazy', 'keep_lazy', (['str', 'SafeText'], {}), '(str, SafeText)\n', (615, 630), False, 'from django.utils.functional import keep_lazy\n'), ((560, 576), 'django.utils.encoding.force_str', 'force_str', (['value'], {}), '(value)\n', (569, 576), False, 'from django.utils.encoding import force_str\n'), ((749, 765), 'django.utils.encoding.force_str', 'force_str', (['value'], {}), '(value)\n', (758, 765), False, 'from django.utils.encoding import force_str\n')]