[ZODB-Dev] more useful TreeSet

John Belmonte jvb at prairienet.org
Tue Sep 23 11:19:12 EDT 2003


Tim Peters wrote:
> IOW, it's explicitly documented that the concrete result type of .keys()
> isn't defined.  I don't expect this will ever change, since a TreeSet can be
> enormous, and TreeSet.keys() has always-- and deliberately --returned a tiny
> object implementing IReadSequence

I see.

> Relief for *this* part is on the way eventually, but not yet in any version
> of ZODB other than ZODB4.  So long as these types have to play nicely with
> Python 2.1, making TreeSets directly iterable is too painful.  ZODB4
> requires Python 2.2 (or later), and Python 2.2 introduced a new iteration
> protocol that doesn't confuse iteration with __getitem__.  The BTree-derived
> types in ZODB4 have already been extended to exploit that new Python
> protocol, and you can iterate over all of them directly in ZODB4 (in
> particular, "for x in some_TreeSet:" works fine in ZODB4).
> 
> Since ZODB3 3.2 will also require Python 2.2 +, if there's enough interest
> these enhancements can be backported to that version of ZODB3 (although
> that's not on my todo list today).

If a future version of ZODB will support iteration, then I'm satisfied. 
  In the meantime, I've made a simple wrapper that will give me 
iteration under ZODB 3.2.  At first I tried to use new iterators, but 
the ZODB persistence system seems to conflict with it somehow.

Thanks for your detailed reply.


class PersistentIntegerSet(IITreeSet):
     """ZODB IITreeSet with Set-like interface

     This class works around issues with the ZODB tree set interface.  It
     adds __getitem__() to allow the container to support iteration.
     """

     """
     # ISSUE: use of iterators seems to clash with ZODB persistence
     def __iter__(self):
         set_items = IITreeSet.keys(self)
         for i in xrange(len(set_items)):
             yield set_items[i]
         raise StopIteration
     """

     def __getitem__(self, index):
         return IITreeSet.keys(self)[index]



-- 
http:// if   le.o  /




More information about the ZODB-Dev mailing list