(name, choices, initial)
return property(getter, setter, deleter)
Define a simple CSS property attribute.
Define a simple CSS property attribute.
Define a simple CSS property attribute .
def validated_property(name, choices, initial):
    "Define a simple CSS property attribute."
    try:
        initial = choices.validate(initial)
    except ValueError:
        # The initial value might be a OtherProperty or Custom class with a value method
        try:
            # Check it has a value attribute
            value_attr = getattr(initial, 'value')

            # Check the value attribute is a callable
            if not callable(value_attr):
                raise ValueError('Initial value "%s" `value` attribute is not callable!' % initial)

        except AttributeError:
            raise ValueError('Initial value "%s" does not have a value attribute!' % initial)

    def getter(self):
        try:
            # Get initial value from other property value. See OtherProperty.
            initial_value = initial.value(self)
        except AttributeError:
            initial_value = initial

        return getattr(self, '_%s' % name, initial_value)

    def setter(self, value):
        try:
            value = choices.validate(value)
        except ValueError:
            raise ValueError("Invalid value '%s' for CSS property '%s'; Valid values are: %s" % (
                value, name, choices
            ))

        if value != getattr(self, '_%s' % name, initial):
            setattr(self, '_%s' % name, value)
            self.dirty = True

    def deleter(self):
        try:
            delattr(self, '_%s' % name)
            self.dirty = True
        except AttributeError:
            # Attribute doesn't exist
            pass

    _CSS_PROPERTIES.add(name)
    return property(getter, setter, deleter)
def validated_property ( name , choices , initial ) : try : initial = choices . validate ( initial ) except ValueError : # The initial value might be a OtherProperty or Custom class with a value method try : # Check it has a value attribute value_attr = getattr ( initial , 'value' ) # Check the value attribute is a callable if not callable ( value_attr ) : raise ValueError ( 'Initial value "%s" `value` attribute is not callable!' % initial ) except AttributeError : raise ValueError ( 'Initial value "%s" does not have a value attribute!' % initial ) def getter ( self ) : try : # Get initial value from other property value. See OtherProperty. initial_value = initial . value ( self ) except AttributeError : initial_value = initial return getattr ( self , '_%s' % name , initial_value ) def setter ( self , value ) : try : value = choices . validate ( value ) except ValueError : raise ValueError ( "Invalid value '%s' for CSS property '%s'; Valid values are: %s" % ( value , name , choices ) ) if value != getattr ( self , '_%s' % name , initial ) : setattr ( self , '_%s' % name , value ) self . dirty = True def deleter ( self ) : try : delattr ( self , '_%s' % name ) self . dirty = True except AttributeError : # Attribute doesn't exist pass _CSS_PROPERTIES . add ( name ) return property ( getter , setter , deleter )