Commits

Mike Bayer committed 5d032c4

- Fixed bug in ``decode.<encoding>`` filter where a non-string object
would not be correctly interpreted in Python 3.

Conflicts:
doc/build/changelog.rst

Comments (0)

Files changed (3)

doc/build/changelog.rst

 
     .. 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
             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

test/test_filters.py

 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):
         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("""
         <%!