Skip to content

Commit

Permalink
Restore Folder pickle forward/backward compatibility with 3.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Feb 25, 2013
1 parent 88e2eee commit ad6a661
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 4 additions & 3 deletions CHANGES.txt
Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/zope/container/folder.py
Expand Up @@ -21,12 +21,24 @@
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

@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 )
11 changes: 10 additions & 1 deletion src/zope/container/tests/test_folder.py
Expand Up @@ -3,6 +3,7 @@
from zope.container.folder import Folder
from zope.container.tests.test_icontainer import TestSampleContainer

import pickle

class Test(TestSampleContainer, TestCase):

Expand All @@ -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)

0 comments on commit ad6a661

Please sign in to comment.