[Zope-CVS] CVS: Packages/pypes/pypes - identity.py:1.20
Casey Duncan
casey at zope.com
Thu Jun 10 00:37:10 EDT 2004
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv5633
Modified Files:
identity.py
Log Message:
Make sure empty identity set can be iterated without being attached to services
=== Packages/pypes/pypes/identity.py 1.19 => 1.20 ===
--- Packages/pypes/pypes/identity.py:1.19 Tue May 25 22:26:17 2004
+++ Packages/pypes/pypes/identity.py Thu Jun 10 00:36:39 2004
@@ -153,13 +153,17 @@
if objs:
self.update(objs)
- def fromIdSet(cls, idset, copy=False, dbconn=None):
+ def fromIdSet(cls, idset, copy=False, dbconn=None, length=None):
"""Alternate constructor to create an identity set from a btree set
of identifiers. If copy is true, then the set is copied, otherwise it
used by the IdentitySet directly. If a copy is not made, then the
idset should not be mutated outside of the set. dbconn is a ZODB
database connection which allows the set to access services before it
is committed.
+
+ If the application knows the length of the set, it can provide the
+ value in the length argument, otherwise the length will be calculated
+ from idset (which may be more expensive).
"""
set = cls()
if copy:
@@ -168,7 +172,9 @@
set._idset = idset
if dbconn is not None:
services.attach(set, dbconn)
- set._length = Length(len(idset))
+ if length is None:
+ length = len(idset)
+ set._length = Length(length)
return set
fromIdSet = classmethod(fromIdSet)
@@ -240,12 +246,13 @@
# If an object in the set is no longer registered None is substituted
# This iterator is lazy and changing the set during iteration
# has undefined results
- identity = services.identity(self)
- for ident in self._idset.keys():
- try:
- yield identity.getObject(ident)
- except IdentityKeyError:
- yield None
+ if self._idset:
+ identity = services.identity(self)
+ for ident in self._idset.keys():
+ try:
+ yield identity.getObject(ident)
+ except IdentityKeyError:
+ yield None
def union(self, other):
return self.__class__.fromIdSet(
More information about the Zope-CVS
mailing list