Actions sur le document
Deepcopy test over the Zope Object Data Base
Filed Under:
Deepcopy test over the Zope Object Data Base
#!/usr/bin/python import copy import transaction from persistent import Persistent from ZODB.DB import DB from ZODB.MappingStorage import MappingStorage class SampleObject(Persistent): pass db = DB(MappingStorage()) conn = db.open() conn.root()['obj1'] = SampleObject() transaction.commit() # Use a different connection to sidestep the ZODB object cache conn2 = db.open() conn2.root()['obj2'] = copy.deepcopy(conn2.root()['obj1']) transaction.commit() conn3 = db.open() obj1 = conn3.root()['obj1'] obj2 = conn3.root()['obj2'] transaction.commit() if obj1 is obj2: print "Fail: instead of a copy we got the same object" elif obj1._p_oid == obj2._p_oid: print "Fail: copy has the same oid" else: print "Looks OK." # Posted by Marius Gedminas to [ZODB-DEV] mail list, 2007/01/23

