[Zope3-checkins] SVN: Zope3/trunk/src/zope/tales/tales.py Fix
Python 2.4 compatibility.
Fred L. Drake, Jr.
fred at zope.com
Wed Jun 23 16:36:10 EDT 2004
Log message for revision 25963:
Fix Python 2.4 compatibility.
Merged from revision 25959 on the ZopeX3-3.0 branch.
Iterator.length() doesn't work the same way for many iterators of
objects that support len() in Python 2.4, since many standard
iterators now do support len(), but don't return what's expected by
the Iterator implementation. This is handled by changing the test to
use an iterator that doesn't provide __len__() in all cases.
The length() method would not work properly for iterators which do
support __len__(); the implementation has been changed so that it
does. One side effect of this is that length() under Python 2.4 works
for more types than it did under Python 2.3, since many of the
iterators for standard types support len() in Python 2.4.
-=-
Modified: Zope3/trunk/src/zope/tales/tales.py
===================================================================
--- Zope3/trunk/src/zope/tales/tales.py 2004-06-23 20:25:59 UTC (rev 25962)
+++ Zope3/trunk/src/zope/tales/tales.py 2004-06-23 20:36:10 UTC (rev 25963)
@@ -468,10 +468,17 @@
>>> it.length()
3
- But you can't get the length if an iterable without a length
- was provided:
+ But you can't get the length of an iterable which doesn't
+ support len():
- >>> it = Iterator('foo', iter({"apple":1, "pear":2}), context)
+ >>> class MyIter(object):
+ ... def __init__(self, seq):
+ ... self._next = iter(seq).next
+ ... def __iter__(self):
+ ... return self
+ ... def next(self):
+ ... return self._next()
+ >>> it = Iterator('foo', MyIter({"apple":1, "pear":2}), context)
>>> it.length()
Traceback (most recent call last):
...
More information about the Zope3-Checkins
mailing list