Test2.__init__(self, initial_shape) 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))
if issubclass(CP, InternalAttributesClass): initialize_internal_attributes(CP) for name in CP._internal: C._internal.append(name) def add_internal_attribute (C, *aname): """add_internal_attribute (C, name, ...) Make attributes name, ... internal in class C. """ initialize_internal_attributes(C) for name in aname: if not name in C._internal: C._internal.append(name) PropertiedClasses.set_property(InternalAttributesClass, 'attributes', InternalAttributesClass._getattributes, nowrite=1, nodelete=1) if __name__ == '__main__': class Test(InternalAttributesClass): def __init__ (self): self.node = None self.parent = None self.__dict__['ro'] = 1 self.__hide = 3 self._p = 4 self.value = 1 PropertiedClasses.set_property(Test, 'ro', nowrite=1, nodelete=1) add_internal_attribute(Test, 'node', 'parent', 'ro')