[Zope3-checkins]
SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/annotation/attribute.py
Merged from trunk:
Jim Fulton
jim at zope.com
Fri Jul 9 18:32:38 EDT 2004
Log message for revision 26383:
Merged from trunk:
r26367 | jim | 2004-07-09 15:41:20 -0400 (Fri, 09 Jul 2004) | 8 lines
AttributeAnnotation adapters no-longer fool around with security or locations
(The location bit was to support security.)
AttributeAnnotation adapters now really only work with unproxied
objects. Generally, they are created by other adapters and,
generally, these other adapters should be trusted adapters.
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/annotation/attribute.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/annotation/attribute.py 2004-07-09 22:31:48 UTC (rev 26382)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/annotation/attribute.py 2004-07-09 22:32:38 UTC (rev 26383)
@@ -15,13 +15,17 @@
$Id$
"""
+
+from UserDict import DictMixin
+
from BTrees.OOBTree import OOBTree
-from interfaces import IAnnotations, IAttributeAnnotatable
-from zope.proxy import removeAllProxies
+
from zope.interface import implements
-from zope.app.location.interfaces import ILocation
-class AttributeAnnotations:
+from interfaces import IAnnotations, IAttributeAnnotatable
+
+
+class AttributeAnnotations(DictMixin):
"""Store annotations in the __annotations__ attribute on a
'IAttributeAnnotatable' object.
"""
@@ -29,58 +33,45 @@
__used_for__ = IAttributeAnnotatable
def __init__(self, obj):
- # We could remove all proxies from obj at this point, but
- # for now, we'll leave it to users of annotations to do that.
- # Users of annotations will typically need to do their own
- # unwrapping anyway.
+ self.obj = obj
- self.wrapped_obj = obj
- self.unwrapped_obj = removeAllProxies(obj)
+ def get(self, key, default=None):
+ """See zope.app.annotation.interfaces.IAnnotations"""
+ annotations = getattr(self.obj, '__annotations__', None)
+ if not annotations:
+ return default
+ return annotations.get(key, default)
+
def __getitem__(self, key):
- """See zope.app.annotation.interfaces.IAnnotations"""
- annotations = getattr(self.unwrapped_obj, '__annotations__', None)
+ annotations = getattr(self.obj, '__annotations__', None)
if annotations is None:
raise KeyError, key
+
return annotations[key]
+
+ def keys(self):
+ annotations = getattr(self.obj, '__annotations__', None)
+ if annotations is None:
+ return []
+ return annotations.keys()
+
def __setitem__(self, key, value):
"""See zope.app.annotation.interfaces.IAnnotations"""
- if ILocation.providedBy(value):
- value.__parent__ = self.unwrapped_obj
-
+
try:
- annotations = self.unwrapped_obj.__annotations__
+ annotations = self.obj.__annotations__
except AttributeError:
- annotations = self.unwrapped_obj.__annotations__ = OOBTree()
+ annotations = self.obj.__annotations__ = OOBTree()
annotations[key] = value
def __delitem__(self, key):
"""See zope.app.interfaces.annotation.IAnnotations"""
try:
- del self.unwrapped_obj.__annotations__[key]
+ annotation = self.obj.__annotations__
except AttributeError:
raise KeyError, key
- def get(self, key, default=None):
- """See zope.app.annotation.interfaces.IAnnotations"""
- try:
- return self.unwrapped_obj.__annotations__.get(key, default)
- except AttributeError:
- # I guess default shouldn't be wrapped.
- return default
-
- def __getattr__(self, name):
- # this method is for getting methods and attributes of the
- # mapping object used to store annotations.
- try:
- attr = getattr(self.unwrapped_obj.__annotations__, name)
- except AttributeError:
- if not hasattr(self.unwrapped_obj, '__annotations__'):
- annotations = self.unwrapped_obj.__annotations__ = OOBTree()
- attr = getattr(annotations, name)
- else:
- raise
-
- return attr
+ del annotation[key]
More information about the Zope3-Checkins
mailing list