[Zope3-checkins] SVN: Zope3/trunk/src/zope/deprecation/deprecation.py Refactored to eliminate dependency on zope.proxy. This was an

Jim Fulton jim at zope.com
Thu Nov 17 15:49:20 EST 2005


Log message for revision 40198:
  Refactored to eliminate dependency on zope.proxy. This was an
  especially bad dependency due to the required C exension in
  zope.proxy.
  

Changed:
  U   Zope3/trunk/src/zope/deprecation/deprecation.py

-=-
Modified: Zope3/trunk/src/zope/deprecation/deprecation.py
===================================================================
--- Zope3/trunk/src/zope/deprecation/deprecation.py	2005-11-17 20:49:16 UTC (rev 40197)
+++ Zope3/trunk/src/zope/deprecation/deprecation.py	2005-11-17 20:49:20 UTC (rev 40198)
@@ -22,7 +22,6 @@
 import sys
 import types
 import warnings
-import zope.proxy
 
 import zope.deprecation
 
@@ -49,31 +48,49 @@
         return '<ShowSwitch %s>' %(self() and 'on' or 'off')
 
 
-class DeprecationProxy(zope.proxy.ProxyBase):
+ogetattr = object.__getattribute__
+class DeprecationProxy(object):
 
-    __slots__ = ('_deprecated',)
-
     def __init__(self, module):
-        super(DeprecationProxy, self).__init__(module)
-        self._deprecated = {}
+        self.__original_module = module
+        self.__deprecated = {}
 
     def deprecate(self, names, message):
         """Deprecate the given names."""
         if not isinstance(names, (tuple, list)):
             names = (names,)
         for name in names:
-            self._deprecated[name] = message
+            self.__deprecated[name] = message
 
     def __getattribute__(self, name):
-        if name != '_deprecated' and name in self._deprecated:
+        if name == 'deprecate' or name.startswith('_DeprecationProxy__'):
+            return ogetattr(self, name)
+
+        if name == '__class__':
+            return types.ModuleType
+        
+        if name in ogetattr(self, '_DeprecationProxy__deprecated'):
             if zope.deprecation.__show__():
                 warnings.warn(
-                    name + ': ' + self._deprecated[name],
+                    name + ': ' + self.__deprecated[name],
                     DeprecationWarning, 2)
 
-        return super(DeprecationProxy, self).__getattribute__(name)
+        return getattr(ogetattr(self, '_DeprecationProxy__original_module'),
+                       name)
 
+    def __setattr__(self, name, value):
+        if name.startswith('_DeprecationProxy__'):
+            return object.__setattr__(self, name, value)
 
+        setattr(self.__original_module, name, value)
+
+    def __delattr__(self, name):
+        if name.startswith('_DeprecationProxy__'):
+            return object.__delattr__(self, name)
+
+        delattr(self.__original_module, name)
+        
+
 class DeprecatedGetProperty(object):
 
     def __init__(self, prop, message):



More information about the Zope3-Checkins mailing list