Beispiel #1
0
    def _execute_action(self, action):
        """ Build placeholders and store action.
        """
        cmd, _self, args_, kwargs_, return_values = (
            action.name,
            action.target,  # target is equivalent to the "self" in a method
            action.args,
            action.kwargs,
            action.return_ids,
        )
        _self = self._fetch_placeholders_from_ids(_self)
        args_ = self._fetch_placeholders_from_ids(args_)
        kwargs_ = self._fetch_placeholders_from_ids(kwargs_)
        return_values = self._fetch_placeholders_from_ids(return_values)

        # We can only instantiate placeholders, filter them
        return_placeholders = []
        Role.nested_object_traversal(return_values,
                                     lambda ph: return_placeholders.append(ph),
                                     PlaceHolder)

        if _self is None:
            method = self._fetch_package_method(cmd)
            response = method(*args_, **kwargs_)
        else:
            response = getattr(_self, cmd)(*args_, **kwargs_)

        if not isinstance(response, (tuple, list)):
            response = (response, )

        PlaceHolder.instantiate_placeholders(return_placeholders, response)
Beispiel #2
0
 def _instantiate_inputs(self, args):
     """ Takes input arguments for this role and generate placeholders.
     """
     input_placeholders = tuple(
         self.placeholders[input_id] for input_id in self.input_placeholder_ids
     )
     PlaceHolder.instantiate_placeholders(input_placeholders, args)
Beispiel #3
0
    def _execute_action(self, action):
        """ Build placeholders and store action.
        """
        cmd, _self, args, kwargs, return_placeholder = (
            action.name,
            action.target,  # target is equivalent to the "self" in a method
            action.args,
            action.kwargs,
            action.return_ids,
        )
        _self = self._fetch_placeholders_from_ids(_self)
        args = self._fetch_placeholders_from_ids(args)
        kwargs = self._fetch_placeholders_from_ids(kwargs)
        return_placeholder = self._fetch_placeholders_from_ids(
            return_placeholder)

        if _self is None:
            response = eval(cmd)(*args, **kwargs)  # nosec
        else:
            response = getattr(_self, cmd)(*args, **kwargs)

        if isinstance(response, PlaceHolder) or isinstance(
                response, FrameworkTensor):
            response = (response, )
            PlaceHolder.instantiate_placeholders(return_placeholder, response)
Beispiel #4
0
    def _execute_action(self, action):
        """ Build placeholders and store action.
        """
        cmd, _self, args_, kwargs_, return_placeholder = (
            action.name,
            action.target,  # target is equivalent to the "self" in a method
            action.args,
            action.kwargs,
            action.return_ids,
        )
        _self = self._fetch_placeholders_from_ids(_self)
        args_ = self._fetch_placeholders_from_ids(args_)
        kwargs_ = self._fetch_placeholders_from_ids(kwargs_)
        return_placeholder = self._fetch_placeholders_from_ids(return_placeholder)

        if _self is None:
            method = self._fetch_package_method(cmd)
            response = method(*args_, **kwargs_)
        else:
            response = getattr(_self, cmd)(*args_, **kwargs_)

        if not isinstance(response, (tuple, list)):
            response = (response,)

        PlaceHolder.instantiate_placeholders(return_placeholder, response)
Beispiel #5
0
        def wrap_stateful_plan(*args):
            role = plan.role
            state = args[-1]
            if 0 < len(role.state.state_placeholders) == len(state) and isinstance(
                state, (list, tuple)
            ):
                state_placeholders = tuple(
                    role.placeholders[ph.id.value] for ph in role.state.state_placeholders
                )
                PlaceHolder.instantiate_placeholders(role.state.state_placeholders, state)
                PlaceHolder.instantiate_placeholders(state_placeholders, state)

            return plan(*args[:-1])
Beispiel #6
0
    def _instantiate_inputs(self, args_):
        """ Takes input arguments for this role and generate placeholders.
        """
        input_placeholders = tuple(self.placeholders[input_id]
                                   for input_id in self.input_placeholder_ids)
        PlaceHolder.instantiate_placeholders(input_placeholders, args_)

        # Last extra argument is a state?
        if (len(self.state.state_placeholders) > 0
                and len(args_) - len(input_placeholders) == 1
                and isinstance(args_[-1], (list, tuple))
                and len(args_[-1]) == len(self.state.state_placeholders)):
            state_placeholders = tuple(self.placeholders[ph.id.value]
                                       for ph in self.state.state_placeholders)
            PlaceHolder.instantiate_placeholders(self.state.state_placeholders,
                                                 args_[-1])
            PlaceHolder.instantiate_placeholders(state_placeholders, args_[-1])