Commit 69d60dc2 authored by Jason Madden's avatar Jason Madden

Add a test for changing the _p_ attributes of broken objects; fix it for _p_changed in pure-python.

parent 5efcab76
...@@ -13,3 +13,4 @@ nosetests.xml ...@@ -13,3 +13,4 @@ nosetests.xml
coverage.xml coverage.xml
*.egg-info *.egg-info
.installed.cfg .installed.cfg
.dir-locals.el
...@@ -409,9 +409,12 @@ class Persistent(object): ...@@ -409,9 +409,12 @@ class Persistent(object):
after = self.__flags | _CHANGED after = self.__flags | _CHANGED
if before != after: if before != after:
self._p_register() self._p_register()
self.__flags = after _OSA(self, '_Persistent__flags', after)
else: else:
self.__flags &= ~_CHANGED flags = self.__flags
flags &= ~_CHANGED
_OSA(self, '_Persistent__flags', flags)
def _p_accessed(self): def _p_accessed(self):
# Notify the jar's pickle cache that we have been accessed. # Notify the jar's pickle cache that we have been accessed.
......
...@@ -1381,6 +1381,28 @@ class _Persistent_Base(object): ...@@ -1381,6 +1381,28 @@ class _Persistent_Base(object):
inst = subclass() inst = subclass()
self.assertEqual(object.__getattribute__(inst,'_v_setattr_called'), False) self.assertEqual(object.__getattribute__(inst,'_v_setattr_called'), False)
def test_can_set__p_attrs_if_subclass_denies_setattr(self):
from persistent._compat import _b
# ZODB defines a PersistentBroken subclass that only lets us
# set things that start with _p, so make sure we can do that
class Broken(self._getTargetClass()):
def __setattr__(self, name, value):
if name.startswith('_p_'):
super(Broken,self).__setattr__(name, value)
else:
raise TypeError("Can't change broken objects")
KEY = _b('123')
jar = self._makeJar()
broken = Broken()
broken._p_oid = KEY
broken._p_jar = jar
broken._p_changed = True
broken._p_changed = 0
class PyPersistentTests(unittest.TestCase, _Persistent_Base): class PyPersistentTests(unittest.TestCase, _Persistent_Base):
def _getTargetClass(self): def _getTargetClass(self):
......
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