def resource_property ( klass , name , * * kwargs ) : klass . PROPERTIES [ name ] = kwargs def getter ( self ) : return getattr ( self , '_%s' % name , kwargs . get ( 'default' , None ) ) if kwargs . get ( 'readonly' , False ) : setattr ( klass , name , property ( getter ) ) else : def setter ( self , value ) : setattr ( self , '_%s' % name , value ) setattr ( klass , name , property ( getter , setter ) )
python add properties using kwargs
Builds a resource object property .
def resource_property(klass, name, **kwargs):
    """Builds a resource object property."""
    klass.PROPERTIES[name] = kwargs

    def getter(self):
        return getattr(self, '_%s' % name, kwargs.get('default', None))

    if kwargs.get('readonly', False):
        setattr(klass, name, property(getter))
    else:
        def setter(self, value):
            setattr(self, '_%s' % name, value)
        setattr(klass, name, property(getter, setter))