[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Memento - IMementoStorable.py:1.1.4.1 AttributeMementoBag.py:1.1.2.6 IAttributeMementoStorable.py:1.1.2.4 memento.zcml:1.1.2.2
Casey Duncan
casey@zope.com
Wed, 10 Apr 2002 11:03:56 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Memento
In directory cvs.zope.org:/tmp/cvs-serv12271
Modified Files:
Tag: Zope-3x-branch
AttributeMementoBag.py IAttributeMementoStorable.py
memento.zcml
Added Files:
Tag: Zope-3x-branch
IMementoStorable.py
Log Message:
Merge Memento changes from security-reorg branch.
* There is a new interface IMementoStorable which is a base interface for all
memento storage interfaces. It is not implemented directly, but used as a
general interface for adapters or views to reference when they need memento
storage. This abstracts the memento storage method from the adapter or view.
* Fixed a bug in AttributeMementoBag where it would do a write on read
when mementos were accessed from an object.
=== 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.4.1 2002/04/10 15:03:55 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.5 => 1.1.2.6 ===
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.3 => 1.1.2.4 ===
$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.2 ===
>
+<!-- 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>