[Zope3-checkins] CVS: Zope3/src/zope/tales - tales.py:1.14

Evan Simpson cvs-admin at zope.org
Wed Nov 5 14:01:53 EST 2003


Update of /cvs-repository/Zope3/src/zope/tales
In directory cvs.zope.org:/tmp/cvs-serv15089

Modified Files:
	tales.py 
Log Message:
Added parity() to Iterator.


=== Zope3/src/zope/tales/tales.py 1.13 => 1.14 ===
--- Zope3/src/zope/tales/tales.py:1.13	Tue Jul 29 14:28:55 2003
+++ Zope3/src/zope/tales/tales.py	Wed Nov  5 14:01:52 2003
@@ -241,6 +241,28 @@
         """
         return 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.parity()
+        'odd'
+        >>> int(bool(it.next()))
+        1
+        >>> it.parity()
+        'even'
+        >>> int(bool(it.next()))
+        1
+        >>> it.parity()
+        'odd'
+        """
+        if self._nextIndex % 2:
+            return 'odd'
+        return 'even'
+
     def letter(self, base=ord('a'), radix=26):
         """Get the iterator position as a lower-case letter
 




More information about the Zope3-Checkins mailing list