Exemplo n.º 1
0
    def update_waiting(self):
        """
        Update function, runs if state is WAITING.

        If input signal has value then node switches to set mode and saves value to variable.

        If input has no signal value then function tries to
        take value from variable and set it to output.
        """
        value = self.get_value(0)
        var_name = f"{self.scope}$" + self.desc_value
        if value is None:
            if var_name in self.variables:
                value = self.variables[var_name]
                if self.value_type is not None:
                    self.set_value(self.value_type(value), 0)
                else:
                    self.set_value(utils.coercion(value), 0)
        else:
            if self.value_type is not None:
                value = self.value_type(value)
                self.set_value(self.value_type(value), 0)
            else:
                value = utils.coercion(value)
                self.set_value(utils.coercion(value), 0)
            self.variables[var_name] = value
        self.state = ACTIVE
Exemplo n.º 2
0
    def update_waiting(self):
        """
        Update function, runs if state is WAITING.

        Function generates value from description (desc_value)
        and saves with specified type to output.
        """
        value = self.desc_value
        if self.value_type is not None:
            self.set_value(self.value_type(value), 0)
        else:
            self.set_value(utils.coercion(value), 0)
        self.state = ACTIVE
Exemplo n.º 3
0
    def update_inactive(self):
        """
        Update function, runs if state is INACTIVE.

        If variable was created then function gets value to output.
        """
        var_name = f"{self.scope}$" + self.desc_value
        if var_name in self.variables:
            value = self.variables[var_name]
            if self.value_type is not None:
                self.set_value(self.value_type(value), 0)
            else:
                self.set_value(utils.coercion(value), 0)
Exemplo n.º 4
0
    def update_waiting(self):
        """
        Update function, runs if state is WAITING.

        Prompt is value from node description (desc_value).
        Function tries to find construction of type {<var name>$<type>} in prompt.

        If it was found then function tries to generate string
        version of value from variable.

        If description wasn't changed then function takes '>>> ' (default) as prompt otherwise desc_value.

        After taking value from input, function saves it to output and changes state to ACTIVE.
        """
        pattern = r"{(?P<var>[^\{\}]+?)(?:\$(?P<type>[^\{\}]+?))?}"
        self.desc_value = saxutils.unescape(self.desc_value)
        # TODO: optimize
        match = list(re.finditer(pattern, self.desc_value))
        while match:
            match = match[0]
            var_name = f"{self.scope}$" + match["var"]
            var_type = match["type"]
            if var_type is not None:
                if var_type in utils.types_default:
                    var_type = utils.types_default[var_type].__class__
                else:
                    var_type = utils.coercion
            if var_name in self.variables:
                var_value = self.variables[var_name]
                if var_type is not None:
                    var_value = var_type(var_value)
                self.desc_value = list(self.desc_value)
                self.desc_value[match.span()[0]:match.span()[1]] = list(
                    str(var_value))
                self.desc_value = "".join(self.desc_value)
            match = list(re.finditer(pattern, self.desc_value))
        prompt = ">>> "
        if self.desc_value:
            if self.desc_value.endswith(" "):
                prompt = self.desc_value
            else:
                prompt = self.desc_value + " "
        if base.Node.ut_send is not None:
            if not base.Node.ut_send:
                logger.log_error("unit tests are empty")
            value = base.Node.ut_send.pop(0)
            value = logger.Color.colored_input(prompt, value=value)
        else:
            value = logger.Color.colored_input(prompt)
        self.set_value(utils.coercion(value), 0)
        self.state = ACTIVE
Exemplo n.º 5
0
    def update_inactive(self):
        """
        Update function, runs if state is INACTIVE.

        Function generates value from description (desc_value)
        and saves with specified type to output.
        """
        value = self.desc_value
        if utils.program_values(value, True):
            value = utils.program_values(value)
        if self.value_type is not None:
            self.set_value(self.value_type(value), 0)
        else:
            self.set_value(utils.coercion(value), 0)
Exemplo n.º 6
0
    def update_waiting(self):
        """
        Update function, runs if state is WAITING.

        Function saves value to variable.
        """
        value = self.get_value(0)
        var_name = f"{self.scope}$" + self.desc_value
        if self.value_type is not None:
            value = self.value_type(value)
        else:
            value = utils.coercion(value)
        self.variables[var_name] = value
        self.state = ACTIVE
Exemplo n.º 7
0
    def update_waiting(self):
        """
        Update function, runs if state is WAITING.

        Function tries to take value from variable and set it to output.
        """
        var_name = f"{self.scope}$" + self.desc_value
        if var_name in self.variables:
            value = self.variables[var_name]
            if self.value_type is not None:
                self.set_value(self.value_type(value), 0)
            else:
                self.set_value(utils.coercion(value), 0)
        self.state = ACTIVE