aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-11-11 15:02:31 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-11-11 15:02:31 -0500
commitf298b36d4e940b1f9e737a64bbd06182da9794fa (patch)
tree97aa9dda9aa89eb7ac6d30dd9578e05da0fcc22f
parent1eb56ef02a7fa825be99ddfb95f217a07dab1cdf (diff)
downloadexternal_python_mako-f298b36d4e940b1f9e737a64bbd06182da9794fa.tar.gz
external_python_mako-f298b36d4e940b1f9e737a64bbd06182da9794fa.tar.bz2
external_python_mako-f298b36d4e940b1f9e737a64bbd06182da9794fa.zip
all tests pass on py3k and py2.7. py2.5/2.4 next
-rw-r--r--mako/ext/babelplugin.py2
-rw-r--r--mako/filters.py3
-rw-r--r--test/test_exceptions.py8
-rw-r--r--test/test_filters.py8
-rw-r--r--test/test_util.py3
5 files changed, 15 insertions, 9 deletions
diff --git a/mako/ext/babelplugin.py b/mako/ext/babelplugin.py
index b620631..2b3f366 100644
--- a/mako/ext/babelplugin.py
+++ b/mako/ext/babelplugin.py
@@ -107,7 +107,7 @@ def extract_nodes(nodes, keywords, comment_tags, options):
translator_comments = \
[comment[1] for comment in translator_comments]
- if not compat.py3k and isinstance(code, str):
+ if not compat.py3k and isinstance(code, compat.text_type):
code = code.encode('ascii', 'backslashreplace')
code = StringIO(code)
for lineno, funcname, messages, python_translator_comments \
diff --git a/mako/filters.py b/mako/filters.py
index bf2f136..428c926 100644
--- a/mako/filters.py
+++ b/mako/filters.py
@@ -37,6 +37,7 @@ try:
except ImportError:
html_escape = legacy_html_escape
+html_escape = legacy_html_escape
def xml_escape(string):
return re.sub(r'([&<"\'>])', lambda m: xml_escapes[m.group()], string)
@@ -164,7 +165,7 @@ def htmlentityreplace_errors(ex):
# Handle encoding errors
bad_text = ex.object[ex.start:ex.end]
text = _html_entities_escaper.escape(bad_text)
- return (str(text), ex.end)
+ return (compat.text_type(text), ex.end)
raise ex
codecs.register_error('htmlentityreplace', htmlentityreplace_errors)
diff --git a/test/test_exceptions.py b/test/test_exceptions.py
index d7feb9a..e860a4c 100644
--- a/test/test_exceptions.py
+++ b/test/test_exceptions.py
@@ -9,7 +9,7 @@ from test.util import result_lines
from test import TemplateTest
from test import requires_pygments_14, requires_no_pygments, \
requires_python_25_or_greater
-
+from mako.compat import u
class ExceptionsTest(TemplateTest):
def test_html_error_template(self):
@@ -159,16 +159,16 @@ ${u'привет'}
@requires_python_25_or_greater
def test_py_utf8_html_error_template(self):
try:
- foo = '日本'
+ foo = u('日本')
raise RuntimeError('test')
except:
html_error = exceptions.html_error_template().render()
if compat.py3k:
assert 'RuntimeError: test' in html_error.decode('utf-8')
- assert "foo = &#39;日本&#39;" in html_error.decode('utf-8')
+ assert "foo = u(&#39;日本&#39;)" in html_error.decode('utf-8')
else:
assert 'RuntimeError: test' in html_error
- assert "foo = u&#39;&#x65E5;&#x672C;&#39;" in html_error
+ assert "foo = u(&#39;&#x65E5;&#x672C;&#39;)" in html_error
def test_py_unicode_error_html_error_template(self):
try:
diff --git a/test/test_filters.py b/test/test_filters.py
index d2a6d6f..7767409 100644
--- a/test/test_filters.py
+++ b/test/test_filters.py
@@ -3,7 +3,8 @@
from mako.template import Template
import unittest
from test import TemplateTest, eq_, requires_python_2
-from .util import result_lines, flatten_result
+from test.util import result_lines, flatten_result
+from mako.compat import u
class FilterTest(TemplateTest):
def test_basic(self):
@@ -87,7 +88,10 @@ class FilterTest(TemplateTest):
some stuff.... ${x}
""", default_filters=['decode.utf8'])
#print t.code
- assert t.render_unicode(x="voix m’a réveillé").strip() == "some stuff.... voix m’a réveillé"
+ eq_(
+ t.render_unicode(x=u("voix m’a réveillé")).strip(),
+ u("some stuff.... voix m’a réveillé")
+ )
def test_custom_default(self):
t = Template("""
diff --git a/test/test_util.py b/test/test_util.py
index a7da274..2683cd7 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -4,6 +4,7 @@ import os
import unittest
from mako import util, exceptions, compat
from test import eq_, skip_if, assert_raises_message
+from mako.compat import u
class UtilTest(unittest.TestCase):
def test_fast_buffer_write(self):
@@ -22,7 +23,7 @@ class UtilTest(unittest.TestCase):
eq_(buf.getvalue(), "string c string d")
def test_fast_buffer_encoded(self):
- s = "drôl m’a rée « S’il"
+ s = u("drôl m’a rée « S’il")
buf = util.FastEncodingBuffer(encoding='utf-8')
buf.write(s[0:10])
buf.write(s[10:])