Esempio n. 1
0
    def removeBehavior(self, *args):
        for behavior in args:
            bh = getBehavior(behavior)
            if (bh.name == self.type) or (bh.spec == self.type):
                raise BehaviorException("Can't remove primary behavior")

            if bh.name not in self.behaviors:
                raise BehaviorException("Behavior is not applied: %s"%bh.name)

            self.behaviors.remove(bh.name)
            if bh.schema:
                self.removeSchema(bh.schema)
            event.notify(BehaviorRemovedEvent(self, bh.name, bh.spec))

        if hasattr(self, '_v__providedBy'):
            del self._v__providedBy
Esempio n. 2
0
    def applyBehavior(self, *args):
        if not self._completed:
            self._completion.append((1, args))
            return

        for behavior in args:
            bh = getBehavior(behavior)
            if bh.name in self.behaviors:
                raise BehaviorException(behavior)

            self.behaviors.append(bh.name)
            if bh.schema:
                self.applySchema(bh.schema)

            event.notify(BehaviorAppliedEvent(self, bh.name, bh.spec))

        if hasattr(self, '_v__providedBy'):
            del self._v__providedBy