diff options
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | mako/compat.py | 5 | ||||
-rw-r--r-- | mako/ext/babelplugin.py | 4 |
3 files changed, 9 insertions, 2 deletions
@@ -6,6 +6,8 @@ is backwards incompatible vs. code that is relying upon a _('') translation to be working within a call tag. +- [bug] The Babel plugin has been repaired to work on Python 3. + 0.8.1 - [bug] Changed setup.py to skip installing markupsafe if Python version is < 2.6 or is between 3.0 and diff --git a/mako/compat.py b/mako/compat.py index 3a4742d..5e9c201 100644 --- a/mako/compat.py +++ b/mako/compat.py @@ -18,6 +18,8 @@ if py3k: binary_type = bytes text_type = str + from io import BytesIO as byte_buffer + def u(s): return s @@ -30,6 +32,9 @@ else: from cStringIO import StringIO except: from StringIO import StringIO + + byte_buffer = StringIO + from urllib import quote_plus, unquote_plus from htmlentitydefs import codepoint2name, name2codepoint string_types = basestring, diff --git a/mako/ext/babelplugin.py b/mako/ext/babelplugin.py index e4feceb..2f6b7fb 100644 --- a/mako/ext/babelplugin.py +++ b/mako/ext/babelplugin.py @@ -113,10 +113,10 @@ def extract_nodes(nodes, keywords, comment_tags, options): translator_comments = \ [comment[1] for comment in translator_comments] - if not compat.py3k and isinstance(code, compat.text_type): + if isinstance(code, compat.text_type): code = code.encode('ascii', 'backslashreplace') - code = StringIO(code) + code = compat.byte_buffer(code) for lineno, funcname, messages, python_translator_comments \ in extract_python(code, keywords, comment_tags, options): yield (node.lineno + (lineno - 1), funcname, messages, |