[Zope3-checkins] CVS: Zope3/lib/python/Zope/ContextWrapper - SimpleMethodWrapper.py:1.7

Jim Fulton jim@zope.com
Sat, 30 Nov 2002 13:42:03 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv12663/lib/python/Zope/ContextWrapper

Modified Files:
	SimpleMethodWrapper.py 
Log Message:

  Changed to allow context markers to be object attributes rather than
  just object dictionary keys. This allows the markers to be defined
  in classes and inherited.



=== Zope3/lib/python/Zope/ContextWrapper/SimpleMethodWrapper.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/ContextWrapper/SimpleMethodWrapper.py:1.6	Tue Nov 12 10:55:58 2002
+++ Zope3/lib/python/Zope/ContextWrapper/SimpleMethodWrapper.py	Sat Nov 30 13:42:02 2002
@@ -36,7 +36,7 @@
 class ContextMethod:
     def __new__(cls, method):
         try:
-            method.__dict__['Zope.ContextWrapper.contextful_get'] = True
+            method.__Zope_ContextWrapper_contextful_get__ = True
         except AttributeError:
             raise TypeError(
                 "Cannot make %s into a contextmethod" % type(method)
@@ -47,21 +47,21 @@
 class ContextProperty(property):
     """A property that provides a context wrapper to its getter and setter
     methods"""
-    __dict__ = {'Zope.ContextWrapper.contextful_get': True,
-                'Zope.ContextWrapper.contextful_set': True}
+    __Zope_ContextWrapper_contextful_get__ = True
+    __Zope_ContextWrapper_contextful_set__ = True
 
 class ContextGetProperty(property):
     """A property that provides a context wrapper to its getter method"""
-    __dict__ = {'Zope.ContextWrapper.contextful_get': True}
+    __Zope_ContextWrapper_contextful_get__ = True
 
 class ContextSetProperty(property):
     """A property that provides a context wrapper to its setter method"""
-    __dict__ = {'Zope.ContextWrapper.contextful_set': True}
+    __Zope_ContextWrapper_contextful_set__ = True
 
 def wrapperCreator(object, context=None, **data):
     if hasattr(object, '__call__'):
-        attrdict = getattr(object.__call__, '__dict__', {})
-        if attrdict.get('Zope.ContextWrapper.contextful_get'):
+        if getattr(object.__call__,
+                   '__Zope_ContextWrapper_contextful_get__', 0):
             return SimpleCallableMethodWrapper(object, context, **data)
 
     return SimpleMethodWrapper(object, context, **data)
@@ -69,30 +69,28 @@
 
 class SimpleMethodWrapper(Wrapper):
 
-    def __getattribute__(self, name, empty_dict={},
-                         getbaseobject=getbaseobject):
+    def __getattribute__(self, name):
         """Support for ContextMethod and ContextProperty.__get__"""
         obj = getbaseobject(self)
         class_ = obj.__class__
         class_value = getattr(class_, name, None)
         if hasattr(class_value, '__get__'):
-            attrdict = getattr(class_value, '__dict__', empty_dict)
-            if attrdict.get('Zope.ContextWrapper.contextful_get'):
+            if getattr(class_value,
+                       '__Zope_ContextWrapper_contextful_get__', 0):
                 return class_value.__get__(self, class_)
             
         return Wrapper.__getattribute__(self, name)
 
 
 
-    def __setattr__(self, name, value, empty_dict={},
-                    getbaseobject=getbaseobject):
+    def __setattr__(self, name, value):
         """Support for ContextProperty.__set__"""
         obj = getbaseobject(self)
         class_ = obj.__class__
         class_value = getattr(class_, name, None)
-        if hasattr(class_value, '__get__'):
-            attrdict = getattr(class_value, '__dict__', empty_dict)
-            if attrdict.get('Zope.ContextWrapper.contextful_set'):
+        if hasattr(class_value, '__set__'):
+            if getattr(class_value,
+                       '__Zope_ContextWrapper_contextful_set__', 0):
                 class_value.__set__(self, value)
                 return
         setattr(obj, name, value)