[Zope-Checkins] CVS: Zope2 - Guards.py:1.4

evan@serenade.digicool.com evan@serenade.digicool.com
Mon, 14 May 2001 17:49:05 -0400


Update of /cvs-repository/Zope2/lib/python/RestrictedPython
In directory serenade:/home/evan/Zope/trunk/lib/python/RestrictedPython

Modified Files:
	Guards.py 
Log Message:
__*attr__ magic methods don't work when you add them after the class is defined, so add them during class definition.



--- Updated File Guards.py in package Zope2 --
--- Guards.py	2001/05/14 16:41:35	1.3
+++ Guards.py	2001/05/14 21:49:05	1.4
@@ -149,16 +149,14 @@
             return len(self.ob)
         def __init__(self, ob):
             self.__dict__['ob'] = ob
-    # Generate class methods
-    d = Wrapper.__dict__
-    for name, error_msg in (
-        ('setitem', 'object does not support item or slice assignment'),
-        ('delitem', 'object does not support item or slice deletion'),
-        ('setattr', 'attribute-less object (assign or del)'),
-        ('delattr', 'attribute-less object (assign or del)'),
-        ):
-        fname = '__%s__' % name
-        d[fname] = _handler('__guarded_%s__' % name, error_msg)
+        __setitem__ = _handler('__guarded_setitem__',
+          'object does not support item or slice assignment')
+        __delitem__ = _handler('__guarded_delitem__',
+          'object does not support item or slice assignment')
+        __setattr__ = _handler('__guarded_setattr__',
+          'attribute-less object (assign or del)')
+        __delattr__ = _handler('__guarded_delattr__',
+          'attribute-less object (assign or del)')
     return Wrapper
 
 def _full_write_guard():