blob: 23a3b152525d5842c57955f4a650cbf0b679bcb5 [file] [log] [blame]
Armin Ronacher07bc6842008-03-31 14:18:49 +02001# -*- 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"""
Armin Ronacher8edbe492008-04-10 20:43:43 +020011
12
13def 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