[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Memento - IMementoStorable.py:1.1.2.1 AttributeMementoBag.py:1.1.2.4.2.1 IAttributeMementoStorable.py:1.1.2.2.2.1 memento.zcml:1.1.2.1.2.1
Casey Duncan
casey@zope.com
Tue, 9 Apr 2002 12:37:13 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Memento
In directory cvs.zope.org:/tmp/cvs-serv11768/Zope/App/OFS/Memento
Modified Files:
Tag: casey-security-reorg-branch
AttributeMementoBag.py IAttributeMementoStorable.py
memento.zcml
Added Files:
Tag: casey-security-reorg-branch
IMementoStorable.py
Log Message:
Mass checkin for security reorganization branch. I will retest this and merge
upon BDFL approval...
=== Added File Zope3/lib/python/Zope/App/OFS/Memento/IMementoStorable.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
$Id: IMementoStorable.py,v 1.1.2.1 2002/04/09 16:36:43 caseman Exp $
"""
from Interface import Interface
from Interface.Attribute import Attribute
class IMementoStorable(Interface):
"""
Marker interfaces for objects that support memento storage.
Classes should not implement this interface directly. Instead they
should implement a derived interface that details how the memento
is to be stored, such as IAttributeMementoStorable.
"""
=== Zope3/lib/python/Zope/App/OFS/Memento/AttributeMementoBag.py 1.1.2.4 => 1.1.2.4.2.1 ===
def __init__(self,obj):
- if not hasattr(obj,'__memobag__'): obj.__memobag__ = OOBTree()
self.obj = obj
+
+ def __getitem__(self, key):
+ memobag = getattr(self.obj, '__memobag__', {})
+ return memobag[key]
+
+ def get(self, key, default=None):
+ try:
+ return self.obj.__memobag__.get(key, default)
+ except AttributeError:
+ return default
def __getattr__(self,attr):
- return getattr(self.obj.__memobag__,attr)
+ try:
+ return getattr(self.obj.__memobag__,attr)
+ except AttributeError:
+ if not hasattr(self.obj, '__memobag__'):
+ memobag = self.obj.__memobag__ = OOBTree()
+ return getattr(memobag, attr)
+ raise
+
=== Zope3/lib/python/Zope/App/OFS/Memento/IAttributeMementoStorable.py 1.1.2.2 => 1.1.2.2.2.1 ===
$Id$
"""
-from Interface import Interface
+from IMementoStorable import IMementoStorable
from Interface.Attribute import Attribute
-class IAttributeMementoStorable(Interface):
+class IAttributeMementoStorable(IMementoStorable):
"""
Marker interfaces giving permission for an IMementoBag adapter to store
data in an an attribute named __memobag__.
=== Zope3/lib/python/Zope/App/OFS/Memento/memento.zcml 1.1.2.1 => 1.1.2.1.2.1 ===
>
+<!-- AttributeMementoBag is the default adapter for all objects -->
<adapter
factory="Zope.App.OFS.Memento.AttributeMementoBag."
- provides="Zope.App.OFS.Memento.IMementoBag."
- for="Zope.App.OFS.Memento.IAttributeMementoStorable." />
+ provides="Zope.App.OFS.Memento.IMementoBag." />
</zopeConfigure>