[Zope3-checkins] CVS: Zope3/src/zope/proxy/context - __init__.py:1.3

Jim Fulton jim@zope.com
Sat, 25 Jan 2003 10:33:23 -0500


Update of /cvs-repository/Zope3/src/zope/proxy/context
In directory cvs.zope.org:/tmp/cvs-serv14157/src/zope/proxy/context

Modified Files:
	__init__.py 
Log Message:
Added ContextAware (zope.proxy.context.ContextAware) base (marker)
class.

All methods (*) and properties of context aware classes are context
aware, meaning that they are bound to context-wrapped instances.

(*) Currently this doesn't apply to operators (__foo__) methods except
__call__ and __getitem__.


=== Zope3/src/zope/proxy/context/__init__.py 1.2 => 1.3 ===
--- Zope3/src/zope/proxy/context/__init__.py:1.2	Wed Dec 25 09:15:16 2002
+++ Zope3/src/zope/proxy/context/__init__.py	Sat Jan 25 10:32:50 2003
@@ -165,6 +165,9 @@
                 )
         return method
 
+class ContextAware:
+    """Marker class indicating that all descriptors should be bound in context
+    """
 
 class ContextProperty(property):
     """A property that provides a context wrapper to its getter and setter
@@ -208,8 +211,11 @@
         class_ = obj.__class__
         class_value = getattr(class_, name, None)
         if hasattr(class_value, '__get__'):
-            if getattr(class_value,
-                       '__Zope_ContextWrapper_contextful_get__', False):
+            if (isinstance(obj, ContextAware)
+                or
+                getattr(class_value,
+                       '__Zope_ContextWrapper_contextful_get__', False)
+                ):
                 return class_value.__get__(self, class_)
 
         return _Wrapper.__getattribute__(self, name)
@@ -220,8 +226,11 @@
         class_ = obj.__class__
         class_value = getattr(class_, name, None)
         if hasattr(class_value, '__set__'):
-            if getattr(class_value,
-                       '__Zope_ContextWrapper_contextful_set__', False):
+            if (isinstance(obj, ContextAware)
+                or
+                getattr(class_value,
+                       '__Zope_ContextWrapper_contextful_set__', False)
+                ):
                 class_value.__set__(self, value)
                 return
         setattr(obj, name, value)