self.file = _File(_parse(reader, self))
self.code = self._generate_python(loader, compress_whitespace)
try:
- self.compiled = compile(self.code, "<template %s>" % self.name,
+ self.compiled = compile(escape.to_unicode(self.code),
+ "<template %s>" % self.name,
"exec")
except Exception:
formatted_code = _format_code(self.code).rstrip()
self.assertEqual(Template("{%!").generate(), b("{%"))
self.assertEqual(Template("{{ 'expr' }} {{!jquery expr}}").generate(),
b("expr {{jquery expr}}"))
+
+ def test_unicode_template(self):
+ template = Template(utf8(u"\u00e9"))
+ self.assertEqual(template.generate(), utf8(u"\u00e9"))
+
+ def test_unicode_literal_expression(self):
+ # Unicode literals should be usable in templates. Note that this
+ # test simulates unicode characters appearing directly in the
+ # template file (with utf8 encoding), i.e. \u escapes would not
+ # be used in the template file itself.
+ if str is unicode:
+ # python 3 needs a different version of this test since
+ # 2to3 doesn't run on template internals
+ template = Template(utf8(u'{{ "\u00e9" }}'))
+ else:
+ template = Template(utf8(u'{{ u"\u00e9" }}'))
+ self.assertEqual(template.generate(), utf8(u"\u00e9"))
class AutoEscapeTest(LogTrapTestCase):