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:45:27 -0400 |
commit | 5d032c477f68e2a2fd7dc4d36377686fed024c56 (patch) | |
tree | 504a4621e66ae14c6a1826d8fd485d0bb6a78ddc | |
parent | c2373cede978a62eb3c142c5ca4bb1a02a32b3ad (diff) | |
download | mako-5d032c477f68e2a2fd7dc4d36377686fed024c56.tar.gz |
- Fixed bug in ``decode.<encoding>`` filter where a non-string object
would not be correctly interpreted in Python 3.
Conflicts:
doc/build/changelog.rst
-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 6b79b30..279a0d5 100644 --- a/doc/build/changelog.rst +++ b/doc/build/changelog.rst @@ -11,6 +11,12 @@ Changelog .. 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: bug, py3k :tickets: 227 Fixed bug in Python parsing logic which would fail on Python 3 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(""" <%! |