diff --git a/CHANGES b/CHANGES index 5d3f2491536462c4229f9cf09a5119ae90ab1abe..8af6d3ae076773a931484a76e22ed0b00eedd15a 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 b181287c7593138b45149e8876d363d7a799dfef..02083fbed66480980b793b4e96c5d2366ba0c57d 100644 --- a/lib/mako/runtime.py +++ b/lib/mako/runtime.py @@ -324,7 +324,9 @@ def _populate_self_namespace(context, template, self_ns=None): 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 6a77570b96eaad3f2eba2428cc39968a478ab735..b1441a4a70149f6d962b689160fe80f3d23c2b47 100644 --- a/lib/mako/template.py +++ b/lib/mako/template.py @@ -122,6 +122,7 @@ class Template(object): 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 0c491f1a11c1c29cb6655fdc5f83a515d0367f62..1727f35dd97dc4dfa16f183917ca69b014047404 100644 --- a/test/template.py +++ b/test/template.py @@ -29,6 +29,10 @@ class EncodingTest(unittest.TestCase): 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! »"""