fixed one bug with blocks, one to go
[jinja2.git] / jinja2 / utils.py
1 # -*- coding: utf-8 -*-
2 """
3     jinja2.utils
4     ~~~~~~~~~~~~
5
6     Utility functions.
7
8     :copyright: 2008 by Armin Ronacher.
9     :license: BSD, see LICENSE for more details.
10 """
11
12
13 def escape(obj, attribute=False):
14     """HTML escape an object."""
15     if hasattr(obj, '__html__'):
16         return obj.__html__()
17     s = unicode(obj) \
18         .replace('&', '&') \
19         .replace('>', '>') \
20         .replace('<', '&lt;')
21     if attribute:
22         s = s.replace('"', '&quot;')
23     return s