[Zope3-checkins] CVS: Zope3/lib/python/ZODB - ConflictResolution.py:1.17
Jeremy Hylton
jeremy@zope.com
Mon, 2 Dec 2002 13:54:50 -0500
Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv18256
Modified Files:
ConflictResolution.py
Log Message:
Refactor getResolver() so that it explicitly gets class metadata.
The change allows bad_classes to be updated whenever we determine that
the class doesn't support resolution.
=== Zope3/lib/python/ZODB/ConflictResolution.py 1.16 => 1.17 ===
--- Zope3/lib/python/ZODB/ConflictResolution.py:1.16 Mon Dec 2 13:10:37 2002
+++ Zope3/lib/python/ZODB/ConflictResolution.py Mon Dec 2 13:54:50 2002
@@ -73,25 +73,29 @@
ref = self._refs[oid] = PersistentReference(oid)
return ref
- def getGhost(self, pickle):
+ def getClassMetadata(self, pickle):
unpickler = self._get_unpickler(pickle)
classmeta = unpickler.load()
- if classmeta in self.bad_classes:
- return None
- else:
- return self._new_object(*classmeta)
+ return classmeta
def getResolver(self, pickle):
# Get the conflict resolution method from a ghost rather
# than actually instantiating the object. _p_resolveConflict()
# is really a static method.
- ghost = self.getGhost(pickle)
+ meta = self.getClassMetadata(pickle)
+ if meta in self.bad_classes:
+ return None
+ try:
+ ghost = self._new_object(*meta)
+ except ImportError:
+ # log failure to import?
+ self.bad_classes[meta] = True
+ return None
if ghost is None:
return None
resolve = getattr(ghost, "_p_resolveConflict", None)
if resolve is None:
- klass = ghost.__class__
- self.bad_classes[klass] = True
+ self.bad_classes[meta] = True
return None
else:
return resolve
@@ -107,22 +111,22 @@
return None
newstate = reader.getState(newpickle)
+ p = self.loadSerial(oid, oldSerial)
+ try:
+ old = reader.getState(p)
+ except (EOFError, PicklingError), err:
+ return None
+ if committedData is None:
+ committedData = self.loadSerial(oid, committedSerial)
+ try:
+ committed = reader.getState(committedData)
+ except (EOFError, PicklingError), err:
+ return None
try:
- p = self.loadSerial(oid, oldSerial)
- try:
- old = reader.getState(p)
- except (EOFError, PicklingError), err:
- return None
- if committedData is None:
- committedData = self.loadSerial(oid, committedSerial)
- try:
- committed = reader.getState(committedData)
- except (EOFError, PicklingError), err:
- return None
resolved = resolve(old, committed, newstate)
-
- writer = ObjectWriter()
- obj = ResolvedObjectAdapter(resolve.im_self, resolved)
- return writer.getState(obj)
except ConflictError:
return None
+
+ writer = ObjectWriter()
+ obj = ResolvedObjectAdapter(resolve.im_self, resolved)
+ return writer.getState(obj)