Горошко Артём Дмитриевич, 321 группа SafeEval 12623 | Гончаров Илья, 321 группа SafeEval 13109 | ||||
---|---|---|---|---|---|
n | 1 | def safeval(exp, globalss=globals(), localss=locals()): | n | 1 | def safeval(exp, glob=globals(), loc=locals()): |
2 | try: | 2 | try: | ||
n | 3 | glob = globalss.copy() | n | 3 | tmp_g = glob.copy() |
4 | loc = localss.copy() | 4 | tmp_l = loc.copy() | ||
5 | except Exception: | 5 | except Exception: | ||
n | 6 | glob = globalss | n | 6 | tmp_g = glob |
7 | loc = localss | 7 | tmp_l = loc | ||
8 | try: | 8 | try: | ||
n | 9 | return eval(exp, glob, loc) | n | 9 | return eval(exp, tmp_g, tmp_l) |
10 | except NameError: | 10 | except NameError: | ||
11 | return exp | 11 | return exp | ||
t | 12 | except Exception as e: | t | 12 | except Exception as E: |
13 | return e | 13 | return E |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|