[Zope-Checkins] CVS: Zope/lib/python/ZTUtils - Iterator.py:1.7.4.4 SimpleTree.py:1.3.4.3 Tree.py:1.6.4.3 Zope.py:1.10.4.3
Chris McDonough
chrism@zope.com
Sat, 26 Oct 2002 15:52:21 -0400
Update of /cvs-repository/Zope/lib/python/ZTUtils
In directory cvs.zope.org:/tmp/cvs-serv31373/lib/python/ZTUtils
Modified Files:
Tag: chrism-install-branch
Iterator.py SimpleTree.py Tree.py Zope.py
Log Message:
Merge with HEAD. Again, sorry for the spew (what's left of it... someone seems to have filtered some of this branch's checkins out).
=== Zope/lib/python/ZTUtils/Iterator.py 1.7.4.3 => 1.7.4.4 ===
--- Zope/lib/python/ZTUtils/Iterator.py:1.7.4.3 Tue Oct 8 17:45:56 2002
+++ Zope/lib/python/ZTUtils/Iterator.py Sat Oct 26 15:51:51 2002
@@ -29,11 +29,10 @@
nextIndex = 0
def __init__(self, seq):
self.seq = seq
- for inner in seqInner, iterInner:
- if inner._supports(seq):
- self._inner = inner
- self._prep_next = inner.prep_next
- return
+ if iterInner._supports(seq, self):
+ self._inner = iterInner
+ self._prep_next = iterInner.prep_next
+ return
raise TypeError, "Iterator does not support %s" % `seq`
def __getattr__(self, name):
@@ -130,48 +129,19 @@
return 0
return not self.prep_next(it)
-class SeqInner(InnerBase):
- '''Inner class for sequence Iterators'''
-
- def _supports(self, ob):
- try: ob[0]
- except (TypeError, AttributeError): return 0
- except: pass
- return 1
-
- def prep_next(self, it):
- i = it.nextIndex
- try:
- it._next = it.seq[i]
- except IndexError:
- it._prep_next = self.no_next
- it.end = 1
- return 0
- it.end = 0
- return 1
-
- def it_length(self, it):
- it.length = l = len(it.seq)
- return l
-
-try:
- StopIteration=StopIteration
-except NameError:
- StopIteration="StopIteration"
-
class IterInner(InnerBase):
- '''Iterator inner class for Python iterators'''
+ '''Iterator inner class for objects with Python iterators'''
- def _supports(self, ob):
+ def _supports(self, ob, it):
try:
- if hasattr(ob, 'next') and (ob is iter(ob)):
- return 1
+ it.iter = iter(ob)
+ return 1
except:
return 0
def prep_next(self, it):
try:
- it._next = it.seq.next()
+ it._next = it.iter.next()
except StopIteration:
it._prep_next = self.no_next
it.end = 1
@@ -192,5 +162,4 @@
return it.item
raise StopIteration
-seqInner = SeqInner()
iterInner = IterInner()
=== Zope/lib/python/ZTUtils/SimpleTree.py 1.3.4.2 => 1.3.4.3 ===
=== Zope/lib/python/ZTUtils/Tree.py 1.6.4.2 => 1.6.4.3 ===
=== Zope/lib/python/ZTUtils/Zope.py 1.10.4.2 => 1.10.4.3 ===