Better handling of eval errors in modules/eval_python.py
This commit is contained in:
parent
11944e348b
commit
3d34896beb
1 changed files with 16 additions and 4 deletions
|
@ -2,12 +2,24 @@ import html, socket
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
EVAL_TEMPLATE = """
|
EVAL_TEMPLATE = """
|
||||||
import sys
|
import StringIO, sys
|
||||||
|
|
||||||
compiled = compile(sys.stdin.read(), "code", "single")
|
compiled = compile(sys.stdin.read(), "code", "single")
|
||||||
result = eval(compiled)
|
|
||||||
print("")
|
old_stdout = sys.stdout
|
||||||
|
stdout = StringIO.StringIO()
|
||||||
|
sys.stdout = stdout
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = eval(compiled)
|
||||||
|
except Exception as e:
|
||||||
|
old_stdout.write(json.dumps({"success" False, "out": str(e)}))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
stdout.write("\n")
|
||||||
if not result == None:
|
if not result == None:
|
||||||
sys.stdout.write(str(result))
|
stdout.write(str(result)+"\n")
|
||||||
|
old_stdout.write(json.dumps({"success" True, "out": stdout.getvalue()}))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EVAL_URL = "https://tpcg.tutorialspoint.com/tpcg.php"
|
EVAL_URL = "https://tpcg.tutorialspoint.com/tpcg.php"
|
||||||
|
|
Loading…
Reference in a new issue