[Zope3-checkins] CVS: Zope3/src/ZODB - Connection.py:1.114.2.2 serialize.py:1.2.10.2

Fred L. Drake, Jr. fred at zope.com
Fri Jan 9 15:30:34 EST 2004


Update of /cvs-repository/Zope3/src/ZODB
In directory cvs.zope.org:/tmp/cvs-serv4906

Modified Files:
      Tag: zope3-zodb3-devel-branch
	Connection.py serialize.py 
Log Message:
restore myhasattr(), with an explanation as to why we do this


=== Zope3/src/ZODB/Connection.py 1.114.2.1 => 1.114.2.2 ===
--- Zope3/src/ZODB/Connection.py:1.114.2.1	Fri Jan  9 14:48:53 2004
+++ Zope3/src/ZODB/Connection.py	Fri Jan  9 15:30:32 2004
@@ -31,8 +31,7 @@
 from ZODB.TmpStore import TmpStore
 from ZODB.Transaction import Transaction, get_transaction
 from ZODB.utils import oid_repr, z64
-from ZODB.serialize \
-     import ObjectWriter, ConnectionObjectReader
+from ZODB.serialize import ObjectWriter, ConnectionObjectReader, myhasattr
 
 global_reset_counter = 0
 
@@ -467,7 +466,7 @@
         # dict update could go on in another thread, but we don't care
         # because we have to check again after the load anyway.
         if (obj._p_oid in self._invalidated
-            and not hasattr(obj, "_p_independent")):
+            and not myhasattr(obj, "_p_independent")):
             # If the object has _p_independent(), we will handle it below.
             self._load_before_or_conflict(obj)
             return
@@ -482,7 +481,7 @@
             self._inv_lock.release()
 
         if invalid:
-            if hasattr(obj, "_p_independent"):
+            if myhasattr(obj, "_p_independent"):
                 # This call will raise a ReadConflictError if something
                 # goes wrong
                 self._handle_independent(obj)


=== Zope3/src/ZODB/serialize.py 1.2.10.1 => 1.2.10.2 ===
--- Zope3/src/ZODB/serialize.py:1.2.10.1	Fri Jan  9 14:48:53 2004
+++ Zope3/src/ZODB/serialize.py	Fri Jan  9 15:30:32 2004
@@ -60,6 +60,17 @@
 
 from ZODB.coptimizations import new_persistent_id
 
+
+def myhasattr(obj, name, _marker=object()):
+    """Make sure we don't mask exceptions like hasattr().
+
+    We don't want exceptions other than AttributeError to be masked,
+    since that too often masks other programming errors.
+    Three-argument getattr() doesn't mask those, so we use that to
+    implement our own hasattr() replacement.
+    """
+    return getattr(obj, name, _marker) is not _marker
+
 def getClassMetadata(obj):
     klass = obj.__class__
     newargs = getattr(klass, "__getnewargs__", None)
@@ -88,7 +99,7 @@
         self._stack = []
         self._p.persistent_id = new_persistent_id(jar, self._stack)
         if jar is not None:
-            assert hasattr(jar, "new_oid")
+            assert myhasattr(jar, "new_oid")
         self._jar = jar
 
     def serialize(self, obj):
@@ -149,7 +160,7 @@
         return unpickler
 
     def _new_object(self, klass, args):
-        if not args and not hasattr(klass, "__getnewargs__"):
+        if not args and not myhasattr(klass, "__getnewargs__"):
             obj = klass.__new__(klass)
         else:
             obj = klass(*args)




More information about the Zope3-Checkins mailing list