Permalink
Browse files

extend ZODBPart to handle __parent__ attribute properly

  • Loading branch information...
1 parent 7a37484 commit c42ecf41b35292a2da5b35a668dc4b800220e3c7 @rnixx rnixx committed May 26, 2011
Showing with 41 additions and 18 deletions.
  1. +38 −15 src/node/ext/zodb/__init__.py
  2. +3 −3 src/node/ext/zodb/__init__.txt
@@ -91,29 +91,56 @@ def __repr__(self):
return "OOBTodict()"
-class PodictStorage(Storage):
+class ZODBPart(Part):
+ """This part requires plumbed class to inherit from Persistent.
+ """
+
+ @extend
+ @property
+ def __parent__(self):
+ """Always expect _v_parent to be set, see __setattr__ and
+ __getitem__.
+ """
+ return self._v_parent
+
+ @extend
+ def __getitem__(self, key):
+ v = self.storage[key]
+ if INode.providedBy(v):
+ v._v_parent = self
+ return v
+
+ @extend
+ def __setattr__(self, name, value):
+ """If name is __parent__, write value to _v_parent. This avoids
+ _p_changed to be set set by Persitent.__setattr__. Using a read/write
+ property for __name__ won't work.
+ """
+ if name == '__parent__':
+ name = '_v_parent'
+ Persistent.__setattr__(self, name, value)
+
+ @extend
+ def __call__(self):
+ transaction.commit()
+
+
+class PodictStorage(ZODBPart, Storage):
@default
@instance_property
def storage(self):
return Podict()
-class OOBTodictStorage(Storage):
+class OOBTodictStorage(ZODBPart, Storage):
@default
@instance_property
def storage(self):
return OOBTodict()
-class ZODBPart(Part):
-
- @extend
- def __call__(self):
- transaction.commit()
-
-
class ZODBAttributes(Part):
implements(IAttributes)
@@ -140,7 +167,6 @@ class ZODBNodeAttributes(Persistent):
Adopt,
DefaultInit,
Nodify,
- ZODBPart,
PodictStorage,
)
allow_non_node_childs = True
@@ -156,20 +182,18 @@ class ZODBNode(Persistent):
DefaultInit,
Nodify,
ZODBAttributes,
- ZODBPart,
PodictStorage,
)
attributes_factory = ZODBNodeAttributes
-
-
+
+
class OOBTNodeAttributes(Persistent):
__metaclass__ = plumber
__plumbing__ = (
NodeChildValidate,
Adopt,
DefaultInit,
Nodify,
- ZODBPart,
OOBTodictStorage,
)
allow_non_node_childs = True
@@ -185,7 +209,6 @@ class OOBTNode(Persistent):
DefaultInit,
Nodify,
ZODBAttributes,
- ZODBPart,
OOBTodictStorage,
)
attributes_factory = OOBTNodeAttributes
@@ -245,7 +245,7 @@ Fill root with some ZODBNodes and check memory usage::
>>> new_size = storage.getSize()
>>> (new_size - old_size) / 1000
- 172L
+ 140L
OOBTNode. Based on OOBTree as storage::
@@ -344,7 +344,7 @@ Fill root with some OOBTNodes and check memory usage::
>>> new_size = storage.getSize()
>>> (new_size - old_size) / 1000
- 168L
+ 136L
Test ``volatile_property``::
@@ -378,4 +378,4 @@ Cleanup test environment::
>>> connection.close()
>>> db.close()
>>> import shutil
- >>> shutil.rmtree(tempdir)
+ >>> shutil.rmtree(tempdir)

0 comments on commit c42ecf4

Please sign in to comment.