[Zodb-checkins] CVS: Zope2/lib/python/ZODB - ConflictResolution.py:1.3

Jim Fulton jim@digicool.com
Tue, 10 Apr 2001 19:13:29 -0400 (EDT)


Update of /cvs-repository/Zope2/lib/python/ZODB
In directory korak:/tmp/cvs-serv12693

Modified Files:
	ConflictResolution.py 
Log Message:
Made tryToResolveConflict available as stand-alone function.



--- Updated File ConflictResolution.py in package Zope2/lib/python/ZODB --
--- ConflictResolution.py	2001/03/15 13:16:26	1.2
+++ ConflictResolution.py	2001/04/10 23:13:28	1.3
@@ -142,60 +142,61 @@
         return None
     return object.data
 
-class ConflictResolvingStorage:
-    "Mix-in class that provides conflict resolution handling for storages"
+def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle):
+    #class_tuple, old, committed, newstate = ('',''), 0, 0, 0
+    try:
+        file=StringIO(newpickle)
+        unpickler=Unpickler(file)
+        prfactory=PersistentReferenceFactory()
+        unpickler.persistent_load=prfactory
+        class_tuple=unpickler.load()[0]
+        if bad_class(class_tuple):
+            #sys.stderr.write(' b%s ' % class_tuple[1]); sys.stderr.flush()
+            return 0
+
+        newstate=unpickler.load()
+        klass=_classFactory(class_tuple[0], class_tuple[1])
+        klass._p_resolveConflict                    
+        inst=klass.__basicnew__()
 
-    def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle):
-        #class_tuple, old, committed, newstate = ('',''), 0, 0, 0
         try:
-            file=StringIO(newpickle)
-            unpickler=Unpickler(file)
-            prfactory=PersistentReferenceFactory()
-            unpickler.persistent_load=prfactory
-            class_tuple=unpickler.load()[0]
-            if bad_class(class_tuple):
-                #sys.stderr.write(' b%s ' % class_tuple[1]); sys.stderr.flush()
-                return 0
-            
-            newstate=unpickler.load()
-            klass=_classFactory(class_tuple[0], class_tuple[1])
-            klass._p_resolveConflict                    
-            inst=klass.__basicnew__()
-            
-            try:
-                resolve=inst._p_resolveConflict
-            except AttributeError:
-                bad_classes[class_tuple]=1
-                #traceback.print_exc()
-                #sys.stderr.write(' b%s ' % class_tuple[1]); sys.stderr.flush()
-                return 0
-            
-            old=state(self, oid, oldSerial, prfactory)
-            committed=state(self, oid, committedSerial, prfactory)
-
-            resolved=resolve(old, committed, newstate)
-                
-            file=StringIO()
-            pickler=Pickler(file,1)
-            pickler.persistent_id=persistent_id
-            pickler.dump(class_tuple)
-            pickler.dump(resolved)
-            #sys.stderr.write(' r%s ' % class_tuple[1]); sys.stderr.flush()
-            return file.getvalue(1)
-        except Exception, v:
-            #print '='*70
-            #print v, v.args
-            #print '='*70
-            #print old
-            #print '='*70
-            #print committed
-            #print '='*70
-            #print newstate
-            #print '='*70
-            
+            resolve=inst._p_resolveConflict
+        except AttributeError:
+            bad_classes[class_tuple]=1
             #traceback.print_exc()
+            #sys.stderr.write(' b%s ' % class_tuple[1]); sys.stderr.flush()
+            return 0
 
-            #sys.stderr.write(' c%s ' % class_tuple[1]); sys.stderr.flush()
+        old=state(self, oid, oldSerial, prfactory)
+        committed=state(self, oid, committedSerial, prfactory)
 
-            return 0
+        resolved=resolve(old, committed, newstate)
+
+        file=StringIO()
+        pickler=Pickler(file,1)
+        pickler.persistent_id=persistent_id
+        pickler.dump(class_tuple)
+        pickler.dump(resolved)
+        #sys.stderr.write(' r%s ' % class_tuple[1]); sys.stderr.flush()
+        return file.getvalue(1)
+    except Exception, v:
+        #print '='*70
+        #print v, v.args
+        #print '='*70
+        #print old
+        #print '='*70
+        #print committed
+        #print '='*70
+        #print newstate
+        #print '='*70
+
+        #traceback.print_exc()
+
+        #sys.stderr.write(' c%s ' % class_tuple[1]); sys.stderr.flush()
+
+        return 0
+
+class ConflictResolvingStorage:
+    "Mix-in class that provides conflict resolution handling for storages"
 
+    tryToResolveConflict=tryToResolveConflict