[Zope3-checkins] CVS: Zope3/lib/python/ZODB - ConflictResolution.py:1.12
Jeremy Hylton
jeremy@zope.com
Thu, 5 Sep 2002 16:20:02 -0400
Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv30389
Modified Files:
ConflictResolution.py
Log Message:
Make tryToResolveConflict a proper method of ConflictResolvingStorage.
Rename self argument to non-method function state(). It wasn't
particularly clear what kind of object self was, and pychecker
complained about it.
=== Zope3/lib/python/ZODB/ConflictResolution.py 1.11 => 1.12 ===
--- Zope3/lib/python/ZODB/ConflictResolution.py:1.11 Wed Jul 3 17:10:10 2002
+++ Zope3/lib/python/ZODB/ConflictResolution.py Thu Sep 5 16:20:01 2002
@@ -30,8 +30,8 @@
return getattr(__import__(location, _globals, _globals, _silly),
name)
-def state(self, oid, serial, prfactory, p=''):
- p=p or self.loadSerial(oid, serial)
+def state(storage, oid, serial, prfactory, p=''):
+ p=p or storage.loadSerial(oid, serial)
file=StringIO(p)
unpickler=Unpickler(file)
unpickler.persistent_load=prfactory
@@ -73,42 +73,41 @@
return None
return object.data
-def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
- committedData=''):
- try:
- file=StringIO(newpickle)
- unpickler=Unpickler(file)
- prfactory=PersistentReferenceFactory()
- unpickler.persistent_load=prfactory
- class_tuple=unpickler.load()[0]
- if bad_class(class_tuple):
- return 0
-
- newstate = unpickler.load()
- klass = _classFactory(class_tuple[0], class_tuple[1])
- inst = klass.__new__(klass)
-
- try:
- resolve = inst._p_resolveConflict
- except AttributeError:
- bad_classes[class_tuple]=1
- return 0
-
- old=state(self, oid, oldSerial, prfactory)
- committed=state(self, oid, committedSerial, prfactory, 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:
- return 0
-
class ConflictResolvingStorage:
"Mix-in class that provides conflict resolution handling for storages"
- tryToResolveConflict=tryToResolveConflict
+ def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
+ committedData=''):
+ try:
+ file = StringIO(newpickle)
+ unpickler = Unpickler(file)
+ prfactory = PersistentReferenceFactory()
+ unpickler.persistent_load = prfactory
+ class_tuple = unpickler.load()[0]
+ if bad_class(class_tuple):
+ return 0
+
+ newstate = unpickler.load()
+ klass = _classFactory(class_tuple[0], class_tuple[1])
+ inst = klass.__new__(klass)
+
+ try:
+ resolve = inst._p_resolveConflict
+ except AttributeError:
+ bad_classes[class_tuple] = 1
+ return 0
+
+ old = state(self, oid, oldSerial, prfactory)
+ committed = state(self, oid, committedSerial, prfactory,
+ 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:
+ return 0