Example #1
0
        

    def __setattr__ (self, name, value):
        self._basic_get('_d')[name] = value
        Test2.__setattr__(self, name, value)
        
class Test4 (PropertiedClasses.PropertiedClass):
    def _basic_set (self, name, value):
        "Restrict acceptable attribute names"
        if name in ['a','b','c']:
            PropertiedClasses.PropertiedClass._basic_set (self, name, value)
        else:
            raise AttributeError, name + ' is not settable.'

PropertiedClasses.set_property (Test, 'shape', Test.getShape, Test.setShape)
assert PropertiedClasses.get_property_g(Test, 'shape').im_func is  Test.getShape.im_func
PropertiedClasses.set_property (Test, 'alwayspositive', acts=Test.validate)
PropertiedClasses.set_property (Test, 'ro', nowrite=1)
PropertiedClasses.set_property (Test, 'ro3', acts = Test.validate)
PropertiedClasses.set_property (Test, 'ro2', nowrite=1)
PropertiedClasses.set_property (Test, 'ro3', nodelete=1)
PropertiedClasses.set_property (Test, 'kenny', actd=Test.kill)
PropertiedClasses.set_property (Test, 'vs', acts=validstring)
PropertiedClasses.set_property (Test2, 'alwayspositive', acts=Test2.validate)
assert PropertiedClasses.get_property_s(Test, 'alwayspositive').im_func is \
                                 Test.validate.im_func
assert PropertiedClasses.get_property_s(Test2, 'alwayspositive').im_func is \
                                 Test2.validate.im_func

t = Test((3,2))
t.a = 1