Exemplo n.º 1
0
 def _del(self, obj, value=None):
     old = self._get(obj)
     try:
         delattr(obj, self._name)
     except AttributeError:
         pass
     else:
         self.handle(AttributeChangeEvent(obj, self, old, self.default))
Exemplo n.º 2
0
    def _set(self, obj, value):
        if not value 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(AttributeChangeEvent(obj, self, old, value))
Exemplo n.º 3
0
    def _set(self, obj, value):
        if value is not None:
            if 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(AttributeChangeEvent(obj, self, old, value))