diff --git a/CHANGES.txt b/CHANGES.txt index 0eb71b8..de6dfae 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,7 +5,8 @@ CHANGES 4.0.0a3 (unreleased) -------------------- -- Nothing changed yet. +- Restore ``Folder`` pickle forward/backward compatibility with + version 3.12.0 after making it inherit from ``BTreeContainer.`` 4.0.0a2 (2013-02-21) @@ -108,7 +109,7 @@ CHANGES - Previous releases should be versioned 3.9.0 as they are not pure bugfix releases and worth a "feature" release, increasing feature version. - + Packages that depend on any changes introduced in version 3.8.2 or 3.8.3 should depend on version 3.9 or greater. @@ -168,7 +169,7 @@ CHANGES 3.7.2 (2009-03-12) ------------------ -- Fix: added missing ComponentLookupError, missing since revision 95429 and +- Fix: added missing ComponentLookupError, missing since revision 95429 and missing in last release. - Adapt to the move of IDefaultViewName from zope.component.interfaces diff --git a/src/zope/container/folder.py b/src/zope/container/folder.py index e9d2d3d..d620102 100644 --- a/src/zope/container/folder.py +++ b/src/zope/container/folder.py @@ -21,8 +21,8 @@ class Folder(btree.BTreeContainer): """The standard Zope Folder implementation.""" - # BBB: The data attribute used to be exposed. This should make it also - # compatible with old pickles. + # BBB: The data attribute used to be exposed. + # For compatibility with existing pickles, we read and write that name @property def data(self): return self._SampleContainer__data @@ -30,3 +30,15 @@ def data(self): @data.setter def data(self, value): self._SampleContainer__data = value + + + def __getstate__( self ): + state = super(Folder,self).__getstate__() + data = state.pop( '_SampleContainer__data' ) + state['data'] = data + return state + + def __setstate__( self, state ): + if 'data' in state and '_SampleContainer__data' not in state: + state['_SampleContainer__data'] = state.pop( 'data' ) + super(Folder,self).__setstate__( state ) diff --git a/src/zope/container/tests/test_folder.py b/src/zope/container/tests/test_folder.py index 6baa01e..6a65bd1 100644 --- a/src/zope/container/tests/test_folder.py +++ b/src/zope/container/tests/test_folder.py @@ -3,6 +3,7 @@ from zope.container.folder import Folder from zope.container.tests.test_icontainer import TestSampleContainer +import pickle class Test(TestSampleContainer, TestCase): @@ -15,6 +16,14 @@ def testDataAccess(self): folder.data = 'foo' self.assertEqual(folder.data, 'foo') + def testPickleCompatibility(self): + folder = self.makeTestObject() + folder['a'] = 1 + self.assertEqual( folder.__getstate__()['data'], folder._SampleContainer__data ) + + folder_clone = pickle.loads( pickle.dumps( folder ) ) + self.assertEqual( folder_clone['a'], folder['a'] ) + + def test_suite(): return makeSuite(Test) -