Commit e13dcef9 authored by Evan Simpson's avatar Evan Simpson

__*attr__ magic methods don't work when you add them after the class is...

__*attr__ magic methods don't work when you add them after the class is defined, so add them during class definition.
parent 596e68c4
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
from __future__ import nested_scopes from __future__ import nested_scopes
__version__='$Revision: 1.3 $'[11:-2] __version__='$Revision: 1.4 $'[11:-2]
import new import new
...@@ -149,16 +149,14 @@ def _write_wrapper(): ...@@ -149,16 +149,14 @@ def _write_wrapper():
return len(self.ob) return len(self.ob)
def __init__(self, ob): def __init__(self, ob):
self.__dict__['ob'] = ob self.__dict__['ob'] = ob
# Generate class methods __setitem__ = _handler('__guarded_setitem__',
d = Wrapper.__dict__ 'object does not support item or slice assignment')
for name, error_msg in ( __delitem__ = _handler('__guarded_delitem__',
('setitem', 'object does not support item or slice assignment'), 'object does not support item or slice assignment')
('delitem', 'object does not support item or slice deletion'), __setattr__ = _handler('__guarded_setattr__',
('setattr', 'attribute-less object (assign or del)'), 'attribute-less object (assign or del)')
('delattr', 'attribute-less object (assign or del)'), __delattr__ = _handler('__guarded_delattr__',
): 'attribute-less object (assign or del)')
fname = '__%s__' % name
d[fname] = _handler('__guarded_%s__' % name, error_msg)
return Wrapper return Wrapper
def _full_write_guard(): def _full_write_guard():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment