-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Labels
Description
My protection function starts this way, so I'm appended the results = printed
line to my code and returning with safe_globals["results"]
at the end of this function. Is this the correct way to collect the print messages? Sometimes I have got error messages like this
"Line 2: SyntaxError: invalid syntax at statement: 'results = printed'"
However results = printed
is not in the original code.
For the follwing input for example
@__builtins__
def interpret(code, my_dict, enable_exec=True):
"""Interprets the given python code inside a safe execution environment"""
warnings.filterwarnings('ignore')
code += "\nresults = printed"
byte_code = compile_restricted(
code,
filename="<string>",
mode="exec",
)