template = Template(utf8("{% apply upper %}foo{% end %}"))
self.assertEqual(template.generate(upper=upper), b("FOO"))
+ def test_unicode_apply(self):
+ def upper(s):
+ return to_unicode(s).upper()
+ template = Template(utf8(u"{% apply upper %}foo \u00e9{% end %}"))
+ self.assertEqual(template.generate(upper=upper), utf8(u"FOO \u00c9"))
+
+ def test_bytes_apply(self):
+ def upper(s):
+ return utf8(to_unicode(s).upper())
+ template = Template(utf8(u"{% apply upper %}foo \u00e9{% end %}"))
+ self.assertEqual(template.generate(upper=upper), utf8(u"FOO \u00c9"))
+
def test_if(self):
template = Template(utf8("{% if x > 4 %}yes{% else %}no{% end %}"))
self.assertEqual(template.generate(x=5), b("yes"))
``ECONNRESET`` error, rather than logging it as an error.
* `HTTPServer` no longer logs an error when it is unable to read a second
request from an HTTP 1.1 keep-alive connection.
+* The ``{% apply %}`` directive now works properly with functions that return
+ both unicode strings and byte strings (previously only byte strings were
+ supported).