[Zodb-checkins] CVS: Zope3/src/zodb - serialize.py:1.14

Jeremy Hylton jeremy@zope.com
Mon, 10 Mar 2003 18:46:00 -0500


Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv1263/src/zodb

Modified Files:
	serialize.py 
Log Message:
Replace dangerous hasattr() with careful getattr().


=== Zope3/src/zodb/serialize.py 1.13 => 1.14 ===
--- Zope3/src/zodb/serialize.py:1.13	Mon Mar 10 14:29:00 2003
+++ Zope3/src/zodb/serialize.py	Mon Mar 10 18:45:57 2003
@@ -91,6 +91,8 @@
     root = PersistentDict()
     return writer.getState(root)
 
+_marker = object()
+
 class ObjectWriter:
 
     def __init__(self, jar=None):
@@ -113,10 +115,9 @@
         If it is persistent, it returns the oid and sometimes a tuple
         with other stuff.
         """
-        if not hasattr(obj, '_p_oid'):
+        oid = getattr(obj, "_p_oid", _marker)
+        if oid is _marker:
             return None
-
-        oid = obj._p_oid
 
         # I'd like to write something like this --
         # if isinstance(oid, types.MemberDescriptor):