Execute trusted code in place.
(code, inputs, entry_point, record_time=False, output_not_none=False)
| 5 | |
| 6 | |
| 7 | def trusted_exec(code, inputs, entry_point, record_time=False, output_not_none=False): |
| 8 | """Execute trusted code in place.""" |
| 9 | exec_globals = {} |
| 10 | exec(code, exec_globals) |
| 11 | fn = exec_globals[entry_point] |
| 12 | |
| 13 | rtime = [] |
| 14 | ret = [] |
| 15 | for inp in inputs: |
| 16 | inp = deepcopy(inp) |
| 17 | if record_time: |
| 18 | start = time.time() |
| 19 | ret.append(fn(*inp)) |
| 20 | rtime.append(time.time() - start) |
| 21 | else: |
| 22 | ret.append(fn(*inp)) |
| 23 | |
| 24 | if output_not_none: |
| 25 | ret = [i is not None for i in ret] |
| 26 | |
| 27 | if record_time: |
| 28 | return ret, rtime |
| 29 | else: |
| 30 | return ret |
| 31 | |
| 32 | |
| 33 | def trusted_check_exec(code, inputs, entry_point): |
no outgoing calls
no test coverage detected