How to use the simpleeval.DEFAULT_OPERATORS.copy function in simpleeval

To help you get started, we’ve selected a few simpleeval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avrae / avrae / cogs5e / funcs / scripting.py View on Github external
def __str__(self):
        return str(self._effect)

    def set_parent(self, parent):
        self._effect.set_parent(parent._effect)


class AliasException(AvraeException):
    pass


def raise_alias_exception(reason):
    raise AliasException(reason)


DEFAULT_OPERATORS = simpleeval.DEFAULT_OPERATORS.copy()
DEFAULT_OPERATORS.pop(ast.Pow)
DEFAULT_FUNCTIONS = simpleeval.DEFAULT_FUNCTIONS.copy()
DEFAULT_FUNCTIONS.update({'floor': floor, 'ceil': ceil, 'round': round, 'len': len, 'max': max, 'min': min,
                          'range': safe_range, 'sqrt': sqrt, 'sum': sum, 'any': any, 'all': all,
                          'roll': simple_roll, 'vroll': verbose_roll, 'load_json': load_json, 'dump_json': dump_json,
                          'time': time.time, 'err': raise_alias_exception})

if __name__ == '__main__':
    evaluator = ScriptingEvaluator()
    while True:
        try:
            evaluator.eval(input("Evaluate: ").strip())
        except Exception as e:
            print(e)
            continue
        print(evaluator.names)