Example #1
0
    def __setattr__(self, name, value):
        # If this isn't an internal value (with a leading underscore), create
        # an attribute update state or raise an error...
        if name[0] != "_":
            try:
                self.__original_state.attribute_update_state(name, value)
                return
            except NotImplementedError:
                raise AttributeError("State does not support attribute setting!")

        # First, set the sttribute value as normal.
        super(State, self).__setattr__(name, value)

        # If this state is not the current clone of the original state, no
        # further action is taken...
        if self.current_clone is not self:
            return

        # If the name has the prefix "_init_" create a corresponding internal
        # attribute without that prefix.  Set it to None for now.  At enter
        # time it will be set to that val of the "_init_" value (resolving any
        # Refs)...
        if name[:6] == "_init_":
            setattr(self, name[5:], None)

        # If we've issued a Ref for this attribute, notify the Ref that its
        # dependencies have changed.
        try:
            ref = self.__issued_refs[name[1:]]
        except KeyError:
            return
        ref.dep_changed()
Example #2
0
    def __setattr__(self, name, value):
        # First, set the sttribute value as normal.
        super(State, self).__setattr__(name, value)

        # If this isn't an internal value (with a leading underscore) or if
        # this state is not the current clone of the original state, no further
        # action is taken...
        if name[0] != "_" or self.current_clone is not self:
            #TODO: error if trying to assign to Ref attribute
            return

        # If the name has the prefix "_init_" create a corresponding internal
        # attribute without that prefix.  Set it to None for now.  At enter
        # time it will be set to that val of the "_init_" value (resolving any
        # Refs)...
        if name[:6] == "_init_":
            setattr(self, name[5:], None)

        # If we've issued a Ref for this attribute, notify the Ref that its
        # dependencies have changed.
        try:
            ref = self.__issued_refs[name[1:]]
        except KeyError:
            return
        ref.dep_changed()