- fixed bug where 'output_encoding' parameter would prevent render_unicode() from returning a unicode object
diff --git a/CHANGES b/CHANGES index 5d3f249..8af6d3a 100644 --- a/CHANGES +++ b/CHANGES
@@ -1,3 +1,7 @@ +0.2.1 +- fixed bug where 'output_encoding' parameter would prevent +render_unicode() from returning a unicode object + 0.2.0 - Speed improvements (as though we needed them, but people contributed and there you go):
diff --git a/lib/mako/runtime.py b/lib/mako/runtime.py index b181287..02083fb 100644 --- a/lib/mako/runtime.py +++ b/lib/mako/runtime.py
@@ -324,7 +324,9 @@ def _render(template, callable_, args, data, as_unicode=False): """create a Context and return the string output of the given template and template callable.""" - if as_unicode or template.output_encoding: + if as_unicode: + buf = util.FastEncodingBuffer(unicode=True) + elif template.output_encoding: buf = util.FastEncodingBuffer(unicode=as_unicode, encoding=template.output_encoding, errors=template.encoding_errors) else: buf = util.StringIO()
diff --git a/lib/mako/template.py b/lib/mako/template.py index 6a77570..b1441a4 100644 --- a/lib/mako/template.py +++ b/lib/mako/template.py
@@ -122,6 +122,7 @@ def render_unicode(self, *args, **data): """render the output of this template as a unicode object.""" + return runtime._render(self, self.callable_, args, data, as_unicode=True) def render_context(self, context, *args, **kwargs):
diff --git a/test/template.py b/test/template.py index 0c491f1..1727f35 100644 --- a/test/template.py +++ b/test/template.py
@@ -29,6 +29,10 @@ def test_unicode(self): template = Template(u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""") assert template.render_unicode() == u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""" + + def test_encoding_doesnt_conflict(self): + template = Template(u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""", output_encoding='utf-8') + assert template.render_unicode() == u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »""" def test_unicode_arg(self): val = u"""Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »"""