forked from CGM_Public/pretix_original
* Upgrade Django to 3.0 and other dependencies to recent versions * Fix otp version contsraint * Remove six dependency * Resolve some warnings * Fix failing tests * Update django-countries * Resolve all RemovedInDjango31Warnings in test suite * Run isort * Fix import * Update PostgreSQL version on travis
31 lines
797 B
Python
31 lines
797 B
Python
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('"'): '"',
|
|
ord("'"): ''',
|
|
ord("="): '=',
|
|
}
|
|
|
|
|
|
@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))
|