Merged in dharland/mako/patch_console_script_mako_render (pull request #5)
Transform mako-render into mako.cmd and add an entry point
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 @@
.. 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/compat.py b/mako/compat.py
index c5ef84b..82b6c05 100644
--- a/mako/compat.py
+++ b/mako/compat.py
@@ -24,6 +24,9 @@
def u(s):
return s
+ def b(s):
+ return s.encode("latin-1")
+
def octal(lit):
return eval("0o" + lit)
@@ -45,6 +48,9 @@
def u(s):
return unicode(s, "utf-8")
+ def b(s):
+ return s
+
def octal(lit):
return eval("0" + lit)
diff --git a/mako/filters.py b/mako/filters.py
index 369cbc3..af7abc2 100644
--- a/mako/filters.py
+++ b/mako/filters.py
@@ -64,7 +64,7 @@
if isinstance(x, compat.text_type):
return x
elif not isinstance(x, compat.binary_type):
- return compat.text_type(str(x), encoding=key)
+ return decode(str(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..5bd9766 100644
--- a/test/test_filters.py
+++ b/test/test_filters.py
@@ -5,6 +5,7 @@
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,33 @@
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")
+ )
+
+ @requires_python_2
+ def test_encode_filter_non_str_we_return_bytes(self):
+ class Foo(object):
+ def __str__(self):
+ return compat.b("å")
+ t = Template("""# coding: utf-8
+ some stuff.... ${x}
+ """, default_filters=['decode.utf8'])
+ eq_(
+ t.render_unicode(x=Foo()).strip(),
+ u("some stuff.... å")
+ )
+
def test_custom_default(self):
t = Template("""
<%!