Игорь Бобров, 428 группа SafeEval 12310 | Гончаров Илья, 321 группа SafeEval 13109 | ||||
---|---|---|---|---|---|
n | 1 | def safeval(data, gl=globals(), lc=locals()): | n | 1 | def safeval(exp, glob=globals(), loc=locals()): |
2 | try: | 2 | try: | ||
n | 3 | g = gl.copy() | n | 3 | tmp_g = glob.copy() |
4 | l = lc.copy() | 4 | tmp_l = loc.copy() | ||
5 | except Exception: | 5 | except Exception: | ||
n | 6 | g = gl | n | 6 | tmp_g = glob |
7 | l = lc | 7 | tmp_l = loc | ||
8 | try: | 8 | try: | ||
n | 9 | return eval(data, g, l) | n | 9 | return eval(exp, tmp_g, tmp_l) |
10 | except NameError: | 10 | except NameError: | ||
t | 11 | return data | t | 11 | return exp |
12 | except Exception as e: | 12 | except Exception as E: | ||
13 | return e | 13 | return E |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|