blob: 23a3b152525d5842c57955f4a650cbf0b679bcb5 [file] [log] [blame]
# -*- coding: utf-8 -*-
"""
jinja2.utils
~~~~~~~~~~~~
Utility functions.
:copyright: 2008 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
def escape(obj, attribute=False):
"""HTML escape an object."""
if hasattr(obj, '__html__'):
return obj.__html__()
s = unicode(obj) \
.replace('&', '&') \
.replace('>', '>') \
.replace('<', '&lt;')
if attribute:
s = s.replace('"', '&quot;')
return s