[Zope3-checkins] CVS: Zope3/src/zope/tales - tales.py:1.16
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Mar 18 09:57:59 EST 2004
Update of /cvs-repository/Zope3/src/zope/tales
In directory cvs.zope.org:/tmp/cvs-serv30862/src/zope/tales
Modified Files:
tales.py
Log Message:
Fix issue 128. The iterator code is now completely up-to-date.
=== Zope3/src/zope/tales/tales.py 1.15 => 1.16 ===
--- Zope3/src/zope/tales/tales.py:1.15 Fri Feb 13 17:31:39 2004
+++ Zope3/src/zope/tales/tales.py Thu Mar 18 09:57:58 2004
@@ -83,7 +83,18 @@
An iterator works as well:
>>> it = Iterator('foo', {"apple":1, "pear":1, "orange":1}, context)
+ >>> it.next()
+ True
+
>>> it = Iterator('foo', {}, context)
+ >>> it.next()
+ False
+
+ >>> it = Iterator('foo', iter((1, 2, 3)), context)
+ >>> it.next()
+ True
+ >>> it.next()
+ True
"""
@@ -99,64 +110,64 @@
try:
self._next = i.next()
except StopIteration:
- self._done = 1
+ self._done = True
else:
- self._done = 0
+ self._done = False
def next(self):
"""Advance the iterator, if possible.
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> bool(it.next())
+ True
>>> context.vars['foo']
'apple'
- >>> int(bool(it.next()))
- 1
+ >>> bool(it.next())
+ True
>>> context.vars['foo']
'pear'
- >>> int(bool(it.next()))
- 1
+ >>> bool(it.next())
+ True
>>> context.vars['foo']
'orange'
- >>> int(bool(it.next()))
- 0
+ >>> bool(it.next())
+ False
>>> it = Iterator('foo', {"apple":1, "pear":1, "orange":1}, context)
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.next()))
- 0
+ >>> bool(it.next())
+ True
+ >>> bool(it.next())
+ True
+ >>> bool(it.next())
+ True
+ >>> bool(it.next())
+ False
>>> it = Iterator('foo', (), context)
- >>> int(bool(it.next()))
- 0
+ >>> bool(it.next())
+ False
>>> it = Iterator('foo', {}, context)
- >>> int(bool(it.next()))
- 0
+ >>> bool(it.next())
+ False
If we can advance, set a local variable to the new value.
"""
# Note that these are *NOT* Python iterators!
if self._done:
- return 0
+ return False
self._item = v = self._next
try:
self._next = self._iter.next()
except StopIteration:
- self._done = 1
- self._last = 1
+ self._done = True
+ self._last = True
self._nextIndex += 1
self._setLocal(self._name, v)
- return 1
+ return True
def index(self):
"""Get the iterator index
@@ -206,18 +217,18 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.even()))
- 0
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.even()))
- 1
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.even()))
- 0
+ >>> it.next()
+ True
+ >>> it.even()
+ False
+ >>> it.next()
+ True
+ >>> it.even()
+ True
+ >>> it.next()
+ True
+ >>> it.even()
+ False
"""
return not (self._nextIndex % 2)
@@ -226,36 +237,36 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.odd()))
- 1
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.odd()))
- 0
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.odd()))
- 1
+ >>> it.next()
+ True
+ >>> it.odd()
+ True
+ >>> it.next()
+ True
+ >>> it.odd()
+ False
+ >>> it.next()
+ True
+ >>> it.odd()
+ True
"""
- return self._nextIndex % 2
+ return bool(self._nextIndex % 2)
def parity(self):
"""Return 'odd' or 'even' depending on the position's parity
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.parity()
'odd'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.parity()
'even'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.parity()
'odd'
"""
@@ -268,16 +279,16 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.letter()
'a'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.letter()
'b'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.letter()
'c'
"""
@@ -295,16 +306,16 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.Letter()
'A'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.Letter()
'B'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.Letter()
'C'
"""
@@ -318,16 +329,16 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.Roman()
'I'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.Roman()
'II'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.Roman()
'III'
"""
@@ -343,16 +354,16 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.roman()
'i'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.roman()
'ii'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.roman()
'iii'
"""
@@ -363,27 +374,26 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.start()))
- 1
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.start()))
- 0
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.start()))
- 0
+ >>> it.next()
+ True
+ >>> it.start()
+ True
+ >>> it.next()
+ True
+ >>> it.start()
+ False
+ >>> it.next()
+ True
+ >>> it.start()
+ False
>>> it = Iterator('foo', {}, context)
- >>> int(bool(it.start()))
- 0
- >>> int(bool(it.next()))
- 0
- >>> int(bool(it.start()))
- 0
-
+ >>> it.start()
+ False
+ >>> it.next()
+ False
+ >>> it.start()
+ False
"""
return self._nextIndex == 1
@@ -392,26 +402,26 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.end()))
- 0
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.end()))
- 0
- >>> int(bool(it.next()))
- 1
- >>> int(bool(it.end()))
- 1
+ >>> it.next()
+ True
+ >>> it.end()
+ False
+ >>> it.next()
+ True
+ >>> it.end()
+ False
+ >>> it.next()
+ True
+ >>> it.end()
+ True
>>> it = Iterator('foo', {}, context)
- >>> int(bool(it.end()))
- 0
- >>> int(bool(it.next()))
- 0
- >>> int(bool(it.end()))
- 0
+ >>> it.end()
+ False
+ >>> it.next()
+ False
+ >>> it.end()
+ False
"""
return self._last
@@ -420,22 +430,22 @@
>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.item()
'apple'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.item()
'pear'
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.item()
'orange'
>>> it = Iterator('foo', {1:2}, context)
- >>> int(bool(it.next()))
- 1
+ >>> it.next()
+ True
>>> it.item()
1
More information about the Zope3-Checkins
mailing list