summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbertas Agejevas <alga@pov.lt>2013-02-22 18:20:16 +0200
committerAlbertas Agejevas <alga@pov.lt>2013-02-22 18:20:16 +0200
commitcdb2fba28d17f6a943264448bee9afcc861e6c47 (patch)
treedb2949b8e12160ceccbc8a8d3b67495262a989bf
parent094891e5a4d5f7664b4b54a159c5e40963417001 (diff)
downloadzope-tales-cdb2fba28d17f6a943264448bee9afcc861e6c47.tar.gz
Found a Py 3.3 problem.
Added basic tests.
-rw-r--r--CHANGES.txt2
-rw-r--r--src/zope/tales/tales.py10
-rw-r--r--src/zope/tales/tests/test_tales.py17
3 files changed, 19 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 3ad6816..0e862c9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,7 +4,7 @@ CHANGES
4.0.1 (unreleased)
------------------
-- Nothing changed yet.
+- Fixed a previously untested Python 3.3 compatibility problem.
4.0.0 (2013-02-14)
diff --git a/src/zope/tales/tales.py b/src/zope/tales/tales.py
index 4fbb33f..fd3295e 100644
--- a/src/zope/tales/tales.py
+++ b/src/zope/tales/tales.py
@@ -113,7 +113,7 @@ class Iterator(object):
else:
self._done = False
- def next(self):
+ def __next__(self):
"""Advance the iterator, if possible.
>>> context = Context(ExpressionEngine(), {})
@@ -168,6 +168,8 @@ class Iterator(object):
self._setLocal(self._name, v)
return True
+ next = __next__ # Python 2 compatibility
+
def index(self):
"""Get the iterator index
@@ -701,10 +703,10 @@ class Context(object):
text = self.evaluate(expr)
if text is self.getDefault() or text is None:
return text
- if isinstance(text, basestring):
+ if isinstance(text, six.string_types):
# text could already be something text-ish, e.g. a Message object
return text
- return unicode(text)
+ return six.text_type(text)
def evaluateStructure(self, expr):
return self.evaluate(expr)
@@ -730,7 +732,7 @@ class Context(object):
def translate(self, msgid, domain=None, mapping=None, default=None):
# custom Context implementations are supposed to customize
# this to call whichever translation routine they want to use
- return unicode(msgid)
+ return six.text_type(msgid)
class TALESTracebackSupplement(object):
diff --git a/src/zope/tales/tests/test_tales.py b/src/zope/tales/tests/test_tales.py
index 82c03bd..853b19f 100644
--- a/src/zope/tales/tests/test_tales.py
+++ b/src/zope/tales/tests/test_tales.py
@@ -16,6 +16,7 @@
import unittest
import re
+import six
from zope.tales import tales
from zope.tales.tests.simpleexpr import SimpleExpr
from doctest import DocTestSuite
@@ -28,7 +29,7 @@ class TALESTests(unittest.TestCase):
# Test sample Iterator class
context = Harness(self)
it = tales.Iterator('name', (), context)
- self.assert_( not it.next(), "Empty iterator")
+ self.assert_( not next(it), "Empty iterator")
context._complete_()
def testIterator1(self):
@@ -36,7 +37,7 @@ class TALESTests(unittest.TestCase):
context = Harness(self)
it = tales.Iterator('name', (1,), context)
context._assert_('setLocal', 'name', 1)
- self.assert_( it.next() and not it.next(), "Single-element iterator")
+ self.assert_(next(it) and not next(it), "Single-element iterator")
context._complete_()
def testIterator2(self):
@@ -46,8 +47,8 @@ class TALESTests(unittest.TestCase):
for c in 'text':
context._assert_('setLocal', 'text', c)
for c in 'text':
- self.assert_(it.next(), "Multi-element iterator")
- self.assert_( not it.next(), "Multi-element iterator")
+ self.assert_(next(it), "Multi-element iterator")
+ self.assert_(not next(it), "Multi-element iterator")
context._complete_()
def testRegisterType(self):
@@ -97,12 +98,18 @@ class TALESTests(unittest.TestCase):
e.registerType('simple', SimpleExpr)
return e.getContext(*(), **kws)
- def testContext0(self):
+ def testContext_evaluate(self):
# Test use of Context
se = self.getContext().evaluate('simple:x')
self.assert_( se == ('simple', 'x'), (
'Improperly evaluated expression %s.' % repr(se)))
+ def testContext_evaluateText(self):
+ # Test use of Context
+ se = self.getContext().evaluateText('simple:x')
+ self.assertTrue(isinstance(se, six.text_type))
+ self.assertEqual(se, "('simple', 'x')")
+
def testVariables(self):
# Test variables
ctxt = self.getContext()