def guard(action_guard):
    """
    Decorator guard refines the criteria for picking an action to run by stating a function
    with THE SAME signature as the guarded action returning a boolean (True if action allowed).
    If the speciified function is unbound or a lambda expression, you must account for 'self',
    e.g. 'lambda self, a, b: a>0'
    """

    def wrap(action_method):

        @functools.wraps(action_method)
        def guard_wrapper(self, *args):
            retval = ActionResult(did_fire=False)
            guard_ok = action_guard(self, *args)
            _log.debug("%s.%s guard returned %s" % (self.name, action_method.__name__, guard_ok))
            if guard_ok:
                retval = action_method(self, *args)
            return retval

        return guard_wrapper
    return wrap
dataset/ETHPy150Open EricssonResearch/calvin-base/calvin/actor/actor.py/guard/original