def evalExpr(self, expr): try: safe_eval('_x["__output"] = (%s)' % expr, self) except: raise return self["_x"]["__output"]
def eval_answer(input, source): global context context.update({ 'answer_to_this_input': 0, 'request_source': source, 'random': random, 'math': math, }) safe_eval('answer_to_this_input = ' + input, context) return context['answer_to_this_input']
def json_load(expr): # strip carriage returns return safe_eval.safe_eval(''.join(str(expr).split('\r')))
def eval(self, key): data = norm_le(self.read(key)) return safe_eval.safe_eval(data)
def execExpr(self, expr): safe_eval(expr, self)
def _safe_eval(eval_string): return safe_eval(eval_string, backstop_underscores=False)
def test_math_module_01(self): self.assertEqual(safe_eval("sqrt(9)", globals=math_namespace), 3)
def test_math_02(self): self.assertEqual(safe_eval("2 ** 13 // 4"), 2048)
def test_math_01(self): self.assertEqual(safe_eval("1 + 1"), 2)
def test_logic_02(self): self.assertEqual(safe_eval("True is not False"), True)
def test_logic_01(self): self.assertEqual(safe_eval("bool(2)"), True)
def test_safe_types(self): for obj, obj_str in safe_python_types: try: self.assertEqual(type(obj), type(safe_eval(obj_str))) except (UnsafeSourceError, SyntaxError): raise
def hasLocation(self, location): try: safe_eval(location, self) return True except: return False
def _expr_fails(self, expr): with self.assertRaises(RuntimeError): safe_eval(expr)