[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Memento - AttributeMementoBag.py:1.1.2.3
Casey Duncan
casey@zope.com
Thu, 28 Mar 2002 16:40:14 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Memento
In directory cvs.zope.org:/tmp/cvs-serv18844
Modified Files:
Tag: Zope-3x-branch
AttributeMementoBag.py
Log Message:
Refactored AttributeMementoBag to use IOBTrees instead of OOBTrees
=== Zope3/lib/python/Zope/App/OFS/Memento/AttributeMementoBag.py 1.1.2.2 => 1.1.2.3 ===
"""
-from Persistence.BTrees.OOBTree import OOBTree
+from Persistence.BTrees.IOBTree import IOBTree
from IMementoBag import IMementoBag
class AttributeMementoBag:
@@ -28,8 +28,23 @@
__implements__ = IMementoBag
def __init__(self,obj):
- if not hasattr(obj,'__memobag__'): obj.__memobag__ = OOBTree()
+ if not hasattr(obj,'__memobag__'): obj.__memobag__ = IOBTree()
self.obj = obj
+
+ def __getitem__(self, key):
+ try:
+ return self.obj.__memobag__[hash(key)]
+ except KeyError:
+ raise KeyError, key
+
+ def get(self, key, default=None):
+ return self.obj.__memobag__.get(hash(key), default)
+
+ def __setitem__(self, key, value):
+ self.obj.__memobag__[hash(key)] = value
- def __getattr__(self,attr):
- return getattr(self.obj.__memobag__,attr)
+ def __delitem__(self, key):
+ try:
+ del self.obj.__memobag__[hash(key)]
+ except KeyError:
+ raise KeyError, key