[Zope3-checkins] CVS: Zope3/src/zope/app -
attributeannotations.py:1.8
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Feb 13 17:24:39 EST 2004
Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv8841/src/zope/app
Modified Files:
attributeannotations.py
Log Message:
Implemented missing __delitem__() method. It is a mystery to me how the
tests passed before. Also updated the tests a bit.
=== Zope3/src/zope/app/attributeannotations.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/attributeannotations.py:1.7 Sun Sep 21 13:30:01 2003
+++ Zope3/src/zope/app/attributeannotations.py Fri Feb 13 17:24:08 2004
@@ -11,23 +11,22 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""
+"""Attribute Annotations implementation
$Id$
"""
-
from zodb.btrees.OOBTree import OOBTree
-from zope.app.interfaces.annotation import IAnnotations
+from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.proxy import removeAllProxies
from zope.interface import implements
from zope.app.interfaces.location import ILocation
class AttributeAnnotations:
- """
- Store annotations in the __annotations__ attribute on a
- IAttributeAnnotatable object.
+ """Store annotations in the __annotations__ attribute on a
+ 'IAttributeAnnotatable' object.
"""
implements(IAnnotations)
+ __used_for__ = IAttributeAnnotatable
def __init__(self, obj):
# We could remove all proxies from obj at this point, but
@@ -39,12 +38,14 @@
self.unwrapped_obj = removeAllProxies(obj)
def __getitem__(self, key):
+ """See zope.app.interfaces.annotation.IAnnotations"""
annotations = getattr(self.unwrapped_obj, '__annotations__', None)
if annotations is None:
raise KeyError, key
return annotations[key]
def __setitem__(self, key, value):
+ """See zope.app.interfaces.annotation.IAnnotations"""
if ILocation.isImplementedBy(value):
value.__parent__ = self.unwrapped_obj
@@ -55,7 +56,15 @@
annotations[key] = value
+ def __delitem__(self, key):
+ """See zope.app.interfaces.annotation.IAnnotations"""
+ try:
+ del self.unwrapped_obj.__annotations__[key]
+ except AttributeError:
+ raise KeyError, key
+
def get(self, key, default=None):
+ """See zope.app.interfaces.annotation.IAnnotations"""
try:
return self.unwrapped_obj.__annotations__.get(key, default)
except AttributeError:
More information about the Zope3-Checkins
mailing list