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

Jeremy Hylton jeremy@zope.com
Mon, 10 Mar 2003 14:29:03 -0500


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

Modified Files:
	serialize.py 
Log Message:
Implement new policy for __getnewargs__() handling.

If a type requires extra arguments to ``__new__``, then instances of
that type must never be in the ghost state.  A ghost is an object with
no state, but if extra arguments are passed to ``__new__`` then the
object has state as soon as it is constructed.  If a ghost object is
found, it is assumed that ``__getnewargs__`` would return None.


=== Zope3/src/zodb/serialize.py 1.12 => 1.13 ===
--- Zope3/src/zodb/serialize.py:1.12	Fri Mar  7 18:51:17 2003
+++ Zope3/src/zodb/serialize.py	Mon Mar 10 14:29:00 2003
@@ -38,6 +38,12 @@
 part of its instances class metadata will be a persistent reference to
 the class.
 
+If a type requires extra arguments to ``__new__``, then instances of
+that type must never be in the ghost state.  A ghost is an object with
+no state, but if extra arguments are passed to ``__new__`` then the
+object has state as soon as it is constructed.  If a ghost object is
+found, it is assumed that ``__getnewargs__`` would return None.
+
 Persistent references
 ---------------------
 
@@ -53,6 +59,8 @@
 changed the class of an object, a new record with new class metadata
 would be written but all the old references would still include the
 old class.
+
+$Id$
 """
 
 __metaclass__ = type
@@ -62,14 +70,14 @@
 from types import StringType, TupleType
 import logging
 
-def getClassMetadata(obj=None, klass=None):
-    if klass is None:
-        klass = obj.__class__
-    # XXX Not sure I understand the obj==None casse
-    newargs = None
-    if obj is not None and hasattr(obj, "__getnewargs__"):
-            newargs = obj.__getnewargs__()
-    return klass, newargs
+def getClassMetadata(obj):
+    if obj._p_state == 3:
+        newargs = None
+    else:
+        newargs = getattr(obj, "__getnewargs__", None)
+        if newargs is not None:
+            newargs = newargs()
+    return obj.__class__, newargs
 
 class RootJar:
     def newObjectId(self):