[Zodb-checkins] CVS: ZODB3/ZODB/zodb4 - conversion.py:1.1.2.4
Fred L. Drake, Jr.
fred at zope.com
Fri Jan 30 16:12:40 EST 2004
Update of /cvs-repository/ZODB3/ZODB/zodb4
In directory cvs.zope.org:/tmp/cvs-serv5843
Modified Files:
Tag: zope3-zodb3-devel-branch
conversion.py
Log Message:
first cut at handling the persistent reference format changes
=== ZODB3/ZODB/zodb4/conversion.py 1.1.2.3 => 1.1.2.4 ===
--- ZODB3/ZODB/zodb4/conversion.py:1.1.2.3 Fri Jan 30 12:32:13 2004
+++ ZODB3/ZODB/zodb4/conversion.py Fri Jan 30 16:12:39 2004
@@ -13,7 +13,8 @@
##############################################################################
"""Nitty-gritty conversion of a ZODB 4 FileStorage to a ZODB 3 FileStorage."""
-from cPickle import dumps
+from cPickle import dumps, Pickler, Unpickler
+from cStringIO import StringIO
from ZODB.FileStorage import FileStorage
from ZODB.zodb4 import z4iterator
@@ -55,9 +56,47 @@
return getattr(self._txn, name)
def __iter__(self):
- for record in iter(self._txn):
+ for record in self._txn:
record.tid = record.serial
+ # transform the data record format
+ # (including persistent references)
+ sio = StringIO(record.data)
+ up = Unpickler(sio)
+ up.persistent_load = PersistentIdentifier
+ data = up.load()
+ sio = StringIO()
+ p = Pickler(sio)
+ p.persistent_id = get_persistent_id
+ p.dump(data)
+ record.data = sio.getvalue()
+ print repr(record.data)
yield record
+
+
+class PersistentIdentifier:
+ def __init__(self, ident):
+ if isinstance(ident, tuple):
+ self._oid, self._class = ident
+ if isinstance(self._class, tuple):
+ self._class, self._args = self._class
+ else:
+ self._args = None
+ else:
+ assert isinstance(ident, str)
+ self._oid = ident
+ self._class = None
+
+
+def get_persistent_id(ob):
+ if isinstance(ob, PersistentIdentifier):
+ if ob._class is None:
+ return dumps(ob._oid)
+ elif ob._args is not None:
+ raise RuntimeError("can't handle __new__ args")
+ else:
+ return dumps((ob._oid, ob._class))
+ else:
+ return None
def str8(s):
More information about the Zodb-checkins
mailing list