示例#1
0
 def _del(self, obj, value=None):
     old = self._get(obj)
     try:
         delattr(obj, self._name)
     except AttributeError:
         pass
     else:
         self.handle(AttributeUpdated(obj, self, old, self.default))
示例#2
0
    def _set(self, obj, value):
        if value not in self.values:
            raise AttributeError("Value should be one of %s" % str(self.values))
        old = self._get(obj)
        if value == old:
            return

        if value == self.default:
            delattr(obj, self._name)
        else:
            setattr(obj, self._name, value)
        self.handle(AttributeUpdated(obj, self, old, value))
示例#3
0
    def _set(self, obj, value):
        if (value is not None and not isinstance(value, self.type)
                and not isinstance(value, str)):
            raise AttributeError(
                "Value should be of type %s" % hasattr(self.type, "__name__")
                and self.type.__name__ or self.type)

        if value == self._get(obj):
            return

        old = self._get(obj)
        if value == self.default and hasattr(obj, self._name):
            delattr(obj, self._name)
        else:
            setattr(obj, self._name, value)
        self.handle(AttributeUpdated(obj, self, old, value))
示例#4
0
 def unlink(self, obj):
     old = self._get(obj)
     self.handle(AttributeUpdated(obj, self, old, old))
示例#5
0
 def unlink(self, obj):
     old = self._get(obj)
     log.debug("Unlink attribute %s.%s", obj, self.name)
     self.handle(AttributeUpdated(obj, self, old, old))