def json_and_html_safe(data): if isinstance(data, str): return escape(data.replace('\\', r'\\')) return data