[Zope3-checkins] CVS: ZODB4/ZODB - ConflictResolution.py:1.14

Jeremy Hylton jeremy@zope.com
Thu, 19 Sep 2002 15:11:03 -0400


Update of /cvs-repository/ZODB4/ZODB
In directory cvs.zope.org:/tmp/cvs-serv27897/ZODB

Modified Files:
	ConflictResolution.py 
Log Message:
Repair the implementation to match 1.12.

The 1.13 checkin was too hasty and had a bunch of sloppy mistakes.



=== ZODB4/ZODB/ConflictResolution.py 1.13 => 1.14 ===
--- ZODB4/ZODB/ConflictResolution.py:1.13	Thu Sep 19 14:22:04 2002
+++ ZODB4/ZODB/ConflictResolution.py	Thu Sep 19 15:11:03 2002
@@ -12,21 +12,12 @@
 # 
 ##############################################################################
 from cStringIO import StringIO
-from cPickle import Unpickler, Pickler
+from cPickle import Pickler, PicklingError
 
 from Transaction.Exceptions import ConflictError
-from ZODB.Serialize import ResolveUnpickler
+from ZODB.Serialize import ResolveUnpickler, getClassMetadata
 
-ResolvedSerial = 'rs'
-
-def state(storage, oid, serial, prfactory, p=''):
-    p=p or storage.loadSerial(oid, serial)
-    file=StringIO(p)
-    unpickler=Unpickler(file)
-    unpickler.persistent_load=prfactory
-    class_tuple=unpickler.load()
-    state=unpickler.load()
-    return state
+ResolvedSerial = "rs"
 
 class PersistentReference:
 
@@ -61,24 +52,32 @@
     "Mix-in class that provides conflict resolution handling for storages"
 
     def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
-                             committedData=''):
-        unpickler = ResolveUnpickler(PersistentReferenceFactory(),
-                                     can_resolve_class)
-        resolve = unpickler.getResolveMethod(newpickle)
+                             committedData=None):
+        unpickler = ResolveUnpickler(PersistentReferenceFactory())
+        resolve = unpickler.getResolver(newpickle)
         if resolve is None:
             return None
-        else:
+        newstate = unpickler.getState(newpickle)
+
+        try:
+            p = self.loadSerial(oid, oldSerial)
             try:
-                p = self.loadSerial(oid, oldSerial)
                 old = unpickler.getState(p)
+            except (EOFError, PicklingError), err:
+                return None
+            if committedData is None:
+                committedData = self.loadSerial(oid, committedSerial)
+            try:
                 committed = unpickler.getState(committedData)
-                resolved = resolve(old, committed, newstate)
-
-                file = StringIO()
-                pickler = Pickler(file,1)
-                pickler.persistent_id = persistent_id
-                pickler.dump(class_tuple)
-                pickler.dump(resolved)
-                return file.getvalue(1)
-            except ConflictError:
+            except (EOFError, PicklingError), err:
                 return None
+            resolved = resolve(old, committed, newstate)
+
+            file = StringIO()
+            pickler = Pickler(file,1)
+            pickler.persistent_id = persistent_id
+            pickler.dump(getClassMetadata(resolve.im_self))
+            pickler.dump(resolved)
+            return file.getvalue(1)
+        except ConflictError:
+            return None