# -*- 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('<', '<') | |
if attribute: | |
s = s.replace('"', '"') | |
return s |