[Zodb-checkins] CVS: ZODB4/src/zodb - serialize.py:1.3

Jeremy Hylton jeremy@zope.com
Tue, 21 Jan 2003 14:32:01 -0500


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

Modified Files:
	serialize.py 
Log Message:
Fix bug that caused too much data to be returned from _dump()
if an earlier call had produced a larger pickle.


=== ZODB4/src/zodb/serialize.py 1.2 => 1.3 ===
--- ZODB4/src/zodb/serialize.py:1.2	Wed Dec 25 09:12:16 2002
+++ ZODB4/src/zodb/serialize.py	Tue Jan 21 14:31:58 2003
@@ -137,13 +137,19 @@
         return NewObjectIterator(self._stack)
 
     def getState(self, obj):
+        d = obj.__getstate__()
+        print "obj", repr(obj), [(k, len(v)) for k, v in d.items()]
         return self._dump(getClassMetadata(obj), obj.__getstate__())
 
     def _dump(self, classmeta, state):
+        # To reuse the existing cStringIO object, we must reset
+        # the file position to 0 and truncate the file after the
+        # new pickle is written.
         self._file.reset()
         self._p.clear_memo()
         self._p.dump(classmeta)
         self._p.dump(state)
+        self._file.truncate()
         return self._file.getvalue()
 
 class NewObjectIterator: