[Zodb-checkins] CVS: Zope3/lib/python/ZODB - Connection.py:1.87 TmpStore.py:1.11 utils.py:1.15

Jeremy Hylton jeremy@zope.com
Mon, 2 Dec 2002 15:22:38 -0500


Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv12174

Modified Files:
	Connection.py TmpStore.py utils.py 
Log Message:
Move Set class to utils and use 2.3 Set when possible.

Make sure that TmpStore always has an _created attribute.  I found a
case where this wasn't true when debugging a different failure.  No
time to write a separate test; I'd blow my stack.


=== Zope3/lib/python/ZODB/Connection.py 1.86 => 1.87 ===
--- Zope3/lib/python/ZODB/Connection.py:1.86	Tue Nov 26 12:41:21 2002
+++ Zope3/lib/python/ZODB/Connection.py	Mon Dec  2 15:22:38 2002
@@ -50,7 +50,7 @@
 from ZODB.POSException import ConflictError, RollbackError
 from ZODB.Serialize import ConnectionObjectReader, \
      getClassMetadata, ObjectWriter
-from ZODB.utils import u64
+from ZODB.utils import u64, Set
 
 from Transaction import get_transaction
 from Persistence.Cache import Cache
@@ -62,14 +62,6 @@
 import time
 from types import StringType, ClassType, TupleType
 
-class Set(dict):
-    def add(self, o):
-        self[o] = 1
-        
-    def addmany(self, L):
-        for o in L:
-            self[o] = 1
-
 class Connection(ExportImport.ExportImport):
     """Object managers for individual object space.
 
@@ -328,8 +320,8 @@
         self._storage.tpc_begin(txn)
         
         # Copy invalidating and creating info from temporary storage:
-        self._modified.addmany(tmp._index)
-        self._created.addmany(tmp._created)
+        self._modified += Set(tmp._index)
+        self._created += tmp._created
         
         for oid in tmp._index:
             data, serial = tmp.load(oid, tmp._bver)
@@ -348,8 +340,7 @@
         self._invalidate_created(tmp._created)
 
     def _invalidate_created(self, created=None):
-        """Dissown any objects newly saved in an uncommitted transaction.
-        """
+        """Dis-own new objects from uncommitted transaction."""
         if created is None:
             created = self._created
             self._created = Set()


=== Zope3/lib/python/ZODB/TmpStore.py 1.10 => 1.11 ===
--- Zope3/lib/python/ZODB/TmpStore.py:1.10	Thu Jul 25 16:56:56 2002
+++ Zope3/lib/python/ZODB/TmpStore.py	Mon Dec  2 15:22:38 2002
@@ -12,7 +12,7 @@
 # 
 ##############################################################################
 from ZODB import POSException
-from ZODB.utils import p64, u64
+from ZODB.utils import p64, u64, Set
 
 import tempfile
 
@@ -33,6 +33,7 @@
         self._index = {}
         # _tindex: map oid to pos for new updates
         self._tindex = {}
+        self._created = Set()
         self._db = None
 
     def close(self):


=== Zope3/lib/python/ZODB/utils.py 1.14 => 1.15 ===
--- Zope3/lib/python/ZODB/utils.py:1.14	Mon Nov 25 14:54:50 2002
+++ Zope3/lib/python/ZODB/utils.py	Mon Dec  2 15:22:38 2002
@@ -36,3 +36,16 @@
             break
         write(d)
         l = l - len(d)
+
+try:
+    from sets import Set
+except ImportError:
+    # This must be Python 2.2, which doesn't have a standard sets module.
+    # ZODB needs only a very limited subset of the Set API.
+    class Set(dict):
+        def add(self, o):
+            self[o] = 1
+        def __add__(self, other):
+            if not isinstance(other, Set):
+                return NotImplemented
+            self.update(other)