[Zodb-checkins] CVS: Zope3/src/zodb - serialize.py:1.12
Jeremy Hylton
jeremy@zope.com
Fri, 7 Mar 2003 18:51:22 -0500
Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv23387
Modified Files:
serialize.py
Log Message:
Revert the last two checkins (temporarily).
Something caused the tests to break.
=== Zope3/src/zodb/serialize.py 1.11 => 1.12 ===
--- Zope3/src/zodb/serialize.py:1.11 Fri Mar 7 18:42:11 2003
+++ Zope3/src/zodb/serialize.py Fri Mar 7 18:51:17 2003
@@ -62,36 +62,14 @@
from types import StringType, TupleType
import logging
-def getClassMetadata(obj):
- """Return 2-tuple that identifies class for ghost creation.
-
- The 2-tuple contains the class of obj and a sequence of
- arguments to pass to the class's __new__() to create a new
- instance. If __new__() takes no extra arguments, the second
- element of the tuple is None.
- """
- # XXX This is a hack. If the object is in a ghost state,
- # we can't know whether its has a __getnewargs__ without
- # loading the object -- but loading the object could fail
- # with a ReadConflictError. Perhaps this can go away
- # when MVCC is here.
-
- # It happens to be the case that the only class I know of
- # that defines a __getnewargs__() does not allow its instances
- # to be ghosts. Maybe that is sufficient.
-
- # Another alternative is to not store the class metadata
- # with the object for references where we can't determine
- # the full metadata. These objects would require a database
- # load in order to create ghosts.
-
- if obj._p_state == 3:
- newargs = None
- else:
- newargs = getattr(obj, "__getnewargs__", None)
- if newargs is not None:
- newargs = newargs()
- return obj.__class__, newargs
+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
class RootJar:
def newObjectId(self):
@@ -127,17 +105,17 @@
If it is persistent, it returns the oid and sometimes a tuple
with other stuff.
"""
- oid = getattr(obj, "_p_oid", None)
- if oid is None:
+ if not hasattr(obj, '_p_oid'):
return None
+ oid = obj._p_oid
+
# I'd like to write something like this --
# if isinstance(oid, types.MemberDescriptor):
# -- but I can't because the type doesn't have a canonical name.
# Instead, we'll assert that an oid must always be a string
- # This case occurs when obj is a class that contains a descriptor
- # for _p_oid.
if not (oid is None or isinstance(oid, StringType)):
+ # XXX log a warning
return None
if oid is None or obj._p_jar is not self._jar: