Commit 42a9ca9f authored by Stephan Richter's avatar Stephan Richter

Merge pull request #2 from NextThought/master

Restore ``Folder`` pickle forward/backward compatibility with 3.12.0. Fixes #1
parents 88e2eeea 672237d8
......@@ -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
......
......@@ -21,8 +21,8 @@ from zope.container import btree, interfaces
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,14 @@ class Folder(btree.BTreeContainer):
@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)
......@@ -3,6 +3,7 @@ from unittest import TestCase, makeSuite
from zope.container.folder import Folder
from zope.container.tests.test_icontainer import TestSampleContainer
import pickle
class Test(TestSampleContainer, TestCase):
......@@ -15,6 +16,14 @@ class Test(TestSampleContainer, TestCase):
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment