(name, parser, wrapper)
return property(getter, setter, deleter)
Define the shorthand CSS font property.
Define the shorthand CSS font property.
Define the shorthand CSS font property .
def validated_shorthand_property(name, parser, wrapper):
    """Define the shorthand CSS font property."""

    def getter(self):
        properties = {}
        for property_name in wrapper.VALID_KEYS:
            try:
                properties[property_name] = getattr(self, '_%s' % property_name)
            except AttributeError:
                pass

        # This is the only place we use the wrapper as a convenience for the user
        return wrapper(**properties) if properties else ''

    def setter(self, value):
        try:
            # A shorthand parser must return a dictionary
            shorthand_dict = parser(value)
        except ValidationError:
            raise ValueError("Invalid value '%s' for CSS property '%s'!" % (value, name))

        # Reset non declared properties to initial values
        used_properties = shorthand_dict.keys()
        for property_name in wrapper.VALID_KEYS:
            if property_name in used_properties:
                setattr(self, property_name, shorthand_dict[property_name])
            else:
                delattr(self, property_name)

        # We do not explicitely set the shorthand property as it is stored in the
        # individual properties it represents
        self.dirty = True

    def deleter(self):
        for property_name in wrapper.VALID_KEYS:
            try:
                delattr(self, property_name)
                self.dirty = True
            except AttributeError:
                # Attribute doesn't exist
                pass

    _CSS_PROPERTIES.add(name)
    return property(getter, setter, deleter)
def validated_shorthand_property ( name , parser , wrapper ) : def getter ( self ) : properties = { } for property_name in wrapper . VALID_KEYS : try : properties [ property_name ] = getattr ( self , '_%s' % property_name ) except AttributeError : pass # This is the only place we use the wrapper as a convenience for the user return wrapper ( * * properties ) if properties else '' def setter ( self , value ) : try : # A shorthand parser must return a dictionary shorthand_dict = parser ( value ) except ValidationError : raise ValueError ( "Invalid value '%s' for CSS property '%s'!" % ( value , name ) ) # Reset non declared properties to initial values used_properties = shorthand_dict . keys ( ) for property_name in wrapper . VALID_KEYS : if property_name in used_properties : setattr ( self , property_name , shorthand_dict [ property_name ] ) else : delattr ( self , property_name ) # We do not explicitely set the shorthand property as it is stored in the # individual properties it represents self . dirty = True def deleter ( self ) : for property_name in wrapper . VALID_KEYS : try : delattr ( self , property_name ) self . dirty = True except AttributeError : # Attribute doesn't exist pass _CSS_PROPERTIES . add ( name ) return property ( getter , setter , deleter )