[Zope3-checkins] CVS: Zope3/src/zope/app - attributeannotations.py:1.7

Jim Fulton jim at zope.com
Sun Sep 21 13:30:02 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv11598/src/zope/app

Modified Files:
	attributeannotations.py 
Log Message:
Stopped using context wrappers. If annotations are ILocations, their
__parent__ is set to the object they annotate.


=== Zope3/src/zope/app/attributeannotations.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/attributeannotations.py:1.6	Tue Jun  3 11:33:55 2003
+++ Zope3/src/zope/app/attributeannotations.py	Sun Sep 21 13:30:01 2003
@@ -19,8 +19,8 @@
 from zodb.btrees.OOBTree import OOBTree
 from zope.app.interfaces.annotation import IAnnotations
 from zope.proxy import removeAllProxies
-from zope.app.context import ContextWrapper
 from zope.interface import implements
+from zope.app.interfaces.location import ILocation
 
 class AttributeAnnotations:
     """
@@ -39,17 +39,28 @@
         self.unwrapped_obj = removeAllProxies(obj)
 
     def __getitem__(self, key):
-        annotations = getattr(self.unwrapped_obj, '__annotations__', {})
-        return ContextWrapper(annotations[key], self.wrapped_obj)
+        annotations = getattr(self.unwrapped_obj, '__annotations__', None)
+        if annotations is None:
+            raise KeyError, key
+        return annotations[key]
+
+    def __setitem__(self, key, value):
+        if ILocation.isImplementedBy(value):
+            value.__parent__ = self.unwrapped_obj
+
+        try:
+            annotations = self.unwrapped_obj.__annotations__
+        except AttributeError:
+            annotations = self.unwrapped_obj.__annotations__ = OOBTree()
+
+        annotations[key] = value
 
     def get(self, key, default=None):
         try:
-            value = self.unwrapped_obj.__annotations__.get(key, default)
+            return self.unwrapped_obj.__annotations__.get(key, default)
         except AttributeError:
             # I guess default shouldn't be wrapped.
             return default
-        else:
-            return ContextWrapper(value, self.wrapped_obj)
 
     def __getattr__(self, name):
         # this method is for getting methods and attributes of the
@@ -62,4 +73,5 @@
                 attr = getattr(annotations, name)
             else:
                 raise
-        return ContextWrapper(attr, self.wrapped_obj)
+            
+        return attr




More information about the Zope3-Checkins mailing list