[Zope3-checkins] CVS: ZODB4/src/zodb - serialize.py:1.8.4.1

Barry Warsaw barry@wooz.org
Mon, 10 Feb 2003 17:44:33 -0500


Update of /cvs-repository/ZODB4/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv29489/src/zodb

Modified Files:
      Tag: opaque-pickles-branch
	serialize.py 
Log Message:
The start of opaque pickles (from the p.o.v. of the storages).  This
will eventually allow us to pass compressed pickles to the storage if
we want.

The approach basically changes store() so that the data argument is a
2-tuple of the pickle and the list of oids referenced in the pickle.
This is the first step in the changes, but currently, only Berkeley
storages natively store the refs included in the store() API call.

Changes here include:

- ObjectWriter.getState(), ObjectCopier.copy() both now return a
  2-tuple of the data and the references, which will be passed as the
  data argument to storages.

- get ZERO from zodb.interfaces and use that consistently

- get rid of the types module


=== ZODB4/src/zodb/serialize.py 1.8 => 1.8.4.1 ===
--- ZODB4/src/zodb/serialize.py:1.8	Wed Feb  5 18:28:34 2003
+++ ZODB4/src/zodb/serialize.py	Mon Feb 10 17:44:32 2003
@@ -57,23 +57,25 @@
 
 __metaclass__ = type
 
-from cStringIO import StringIO
-import cPickle
-from types import StringType, TupleType
 import logging
+import cPickle
+from cStringIO import StringIO
+
+from zodb.interfaces import ZERO
+
 
 def getClassMetadata(obj=None, klass=None):
     if klass is None:
         klass = obj.__class__
-    # XXX Not sure I understand the obj==None casse
+    # XXX Not sure I understand the obj==None case
     newargs = None
     if obj is not None and hasattr(obj, "__getnewargs__"):
-            newargs = obj.__getnewargs__()
+        newargs = obj.__getnewargs__()
     return klass, newargs
 
 class RootJar:
     def newObjectId(self):
-        return "\0" * 8
+        return ZERO
 
 def getDBRoot():
     """Return a serialized database root object."""
@@ -114,7 +116,7 @@
         # 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
-        if not (oid is None or isinstance(oid, StringType)):
+        if not (oid is None or isinstance(oid, str)):
             # XXX log a warning
             return None
 
@@ -135,7 +137,10 @@
 
     def getState(self, obj):
         d = obj.__getstate__()
-        return self._dump(getClassMetadata(obj), obj.__getstate__())
+        data = self._dump(getClassMetadata(obj), obj.__getstate__())
+        # XXX we should calculate oids while we're pickling the data
+        refs = findrefs(data)
+        return data, refs
 
     def _dump(self, classmeta, state):
         # To reuse the existing cStringIO object, we must reset
@@ -228,7 +233,7 @@
 
     def _persistent_load(self, oid):
         # persistent_load function to pass to ObjectReader
-        if isinstance(oid, TupleType):
+        if isinstance(oid, tuple):
             # XXX We get here via new_persistent_id()
 
             # Quick instance reference.  We know all we need to know
@@ -265,7 +270,7 @@
         self._cache = oids
 
     def _persistent_load(self, oid):
-        if isinstance(oid, TupleType):
+        if isinstance(oid, tuple):
             oid, classmeta = oid
         else:
             classmeta = None
@@ -299,7 +304,8 @@
 
     def copy(self, pickle):
         classmeta, state = self._reader.readPickle(pickle)
-        return self._writer._dump(classmeta, state)
+        data = self._writer._dump(classmeta, state)
+        return data, findrefs(data)
 
 def findrefs(p):
     f = StringIO(p)
@@ -313,7 +319,7 @@
     # Iterator over L and convert persistent references to simple oids.
     oids = []
     for ref in L:
-        if isinstance(ref, TupleType):
+        if isinstance(ref, tuple):
             oids.append(ref[0])
         else:
             oids.append(ref)