[Zope3-checkins] CVS: ZODB4/ZODB/tests - StorageTestBase.py:1.18
Jeremy Hylton
jeremy@zope.com
Thu, 19 Sep 2002 15:14:07 -0400
Update of /cvs-repository/ZODB4/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv28328/ZODB/tests
Modified Files:
StorageTestBase.py
Log Message:
Rewrite zodb_unpickle() using ZODB.Serialize.
=== ZODB4/ZODB/tests/StorageTestBase.py 1.17 => 1.18 ===
--- ZODB4/ZODB/tests/StorageTestBase.py:1.17 Wed Jul 24 19:12:46 2002
+++ ZODB4/ZODB/tests/StorageTestBase.py Thu Sep 19 15:14:06 2002
@@ -27,6 +27,7 @@
from cPickle import Pickler, Unpickler
from cStringIO import StringIO
+from ZODB.Serialize import ConnectionUnpickler
from ZODB.ZTransaction import Transaction
from ZODB.tests.MinPO import MinPO
@@ -38,47 +39,18 @@
f = StringIO()
p = Pickler(f, 1)
klass = obj.__class__
- assert not hasattr(obj, '__getinitargs__'), "not ready for constructors"
- args = None
-
mod = getattr(klass, '__module__', None)
- if mod is not None:
- klass = mod, klass.__name__
-
state = obj.__getstate__()
- p.dump((klass, args))
+ # XXX
+ p.dump((mod, klass.__name__, None))
p.dump(state)
return f.getvalue(1)
def zodb_unpickle(data):
"""Unpickle an object stored using the format expected by ZODB."""
- f = StringIO(data)
- u = Unpickler(f)
- klass_info = u.load()
- if isinstance(klass_info, types.TupleType):
- if isinstance(klass_info[0], types.TupleType):
- modname, klassname = klass_info[0]
- args = klass_info[1]
- else:
- modname, klassname = klass_info
- args = None
- if modname == "__main__":
- ns = globals()
- else:
- mod = import_helper(modname)
- ns = mod.__dict__
- try:
- klass = ns[klassname]
- except KeyError:
- sys.stderr.write("can't find %s in %s" % (klassname,
- repr(ns)))
- inst = klass()
- else:
- raise ValueError, "expected class info: %s" % repr(klass_info)
- state = u.load()
- inst.__setstate__(state)
- return inst
+ u = ConnectionUnpickler(None, {})
+ return u.getObject(data)
def handle_all_serials(oid, *args):
"""Return dict of oid to serialno from store() and tpc_vote().