diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-04-20 21:43:55 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-04-20 21:43:55 -0400 |
commit | 81f27474ff7795a59bf1547ab7042b6ae36ea907 (patch) | |
tree | b3be1581a54c7468ce92f6d5dcb9fc238dcf56d5 | |
parent | 6d96ef8c2d454622070d2d63ed0a2a911cde3834 (diff) | |
download | mako-w_json_metadata.tar.gz |
- Fixed bug in ``decode.<encoding>`` filter where a non-string objectw_json_metadata
would not be correctly interpreted in Python 3.
-rw-r--r-- | doc/build/changelog.rst | 6 | ||||
-rw-r--r-- | mako/filters.py | 2 | ||||
-rw-r--r-- | test/test_filters.py | 11 |
3 files changed, 17 insertions, 2 deletions
diff --git a/doc/build/changelog.rst b/doc/build/changelog.rst index 27c12e5..81ded29 100644 --- a/doc/build/changelog.rst +++ b/doc/build/changelog.rst @@ -10,6 +10,12 @@ Changelog :released: .. change:: + :tags: bug, py3k + + Fixed bug in ``decode.<encoding>`` filter where a non-string object + would not be correctly interpreted in Python 3. + + .. change:: :tags: feature Template modules now generate a JSON "metadata" structure at the bottom diff --git a/mako/filters.py b/mako/filters.py index 369cbc3..ab7925f 100644 --- a/mako/filters.py +++ b/mako/filters.py @@ -64,7 +64,7 @@ class Decode(object): if isinstance(x, compat.text_type): return x elif not isinstance(x, compat.binary_type): - return compat.text_type(str(x), encoding=key) + return compat.text_type(x) else: return compat.text_type(x, encoding=key) return decode diff --git a/test/test_filters.py b/test/test_filters.py index cf292ed..f0c55c6 100644 --- a/test/test_filters.py +++ b/test/test_filters.py @@ -5,6 +5,7 @@ import unittest from test import TemplateTest, eq_, requires_python_2 from test.util import result_lines, flatten_result from mako.compat import u +from mako import compat class FilterTest(TemplateTest): def test_basic(self): @@ -94,12 +95,20 @@ class FilterTest(TemplateTest): t = Template("""# coding: utf-8 some stuff.... ${x} """, default_filters=['decode.utf8']) - #print t.code eq_( t.render_unicode(x=u("voix m’a réveillé")).strip(), u("some stuff.... voix m’a réveillé") ) + def test_encode_filter_non_str(self): + t = Template("""# coding: utf-8 + some stuff.... ${x} + """, default_filters=['decode.utf8']) + eq_( + t.render_unicode(x=3).strip(), + u("some stuff.... 3") + ) + def test_custom_default(self): t = Template(""" <%! |