[Zope3-checkins] CVS: Zope3/lib/python/ZODB - ConflictResolution.py:1.18 Serialize.py:1.7

Jeremy Hylton jeremy@zope.com
Mon, 2 Dec 2002 14:17:02 -0500


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

Modified Files:
	ConflictResolution.py Serialize.py 
Log Message:
Revise handling of bad classes during ConflictResolution.

Extend test suite to verify that classes are recognized as
unresolvable().  This, unfortunately, extends into the ZEO test suite,
because a ZEO client doesn't know enough to support the test.


=== Zope3/lib/python/ZODB/ConflictResolution.py 1.17 => 1.18 ===
--- Zope3/lib/python/ZODB/ConflictResolution.py:1.17	Mon Dec  2 13:54:50 2002
+++ Zope3/lib/python/ZODB/ConflictResolution.py	Mon Dec  2 14:17:00 2002
@@ -20,7 +20,7 @@
 from cPickle import Pickler, PicklingError
 
 from Transaction.Exceptions import ConflictError
-from ZODB.Serialize import BaseObjectReader, ObjectWriter
+from ZODB.Serialize import BaseObjectReader, ObjectWriter, getClassMetadata
 
 ResolvedSerial = "rs"
 
@@ -62,6 +62,10 @@
 
 class ResolveObjectReader(BaseObjectReader):
 
+    # The bad_classes attribute tracks all classes for which an
+    # _p_resolveConflict() method could not be found.  It is used
+    # to avoid repeating work to load classes when it is known
+    # that they can't be imported or don't resolve conflicts.
     bad_classes = {}
 
     def __init__(self):
@@ -72,6 +76,17 @@
         if ref is None:
             ref = self._refs[oid] = PersistentReference(oid)
         return ref
+
+    def unresolvable(cls, klass):
+        """Returns True if class does not support conflict resolution.
+
+        The exact rules are implementation dependent.  This method was
+        written to make testing easier.
+        """
+        meta = getClassMetadata(klass=klass)
+        return meta in cls.bad_classes
+
+    unresolvable = classmethod(unresolvable)
 
     def getClassMetadata(self, pickle):
         unpickler = self._get_unpickler(pickle)


=== Zope3/lib/python/ZODB/Serialize.py 1.6 => 1.7 ===
--- Zope3/lib/python/ZODB/Serialize.py:1.6	Mon Dec  2 13:10:37 2002
+++ Zope3/lib/python/ZODB/Serialize.py	Mon Dec  2 14:17:00 2002
@@ -61,8 +61,9 @@
         mod = getattr(mod, part)
     return getattr(mod, name)
 
-def getClassMetadata(object):
-    klass = object.__class__
+def getClassMetadata(object=None, klass=None):
+    if klass is None:
+        klass = object.__class__
     module = klass.__module__
     classname = klass.__name__
     if hasattr(object, "__getnewargs__"):