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