From cfb9fa1c2e3fc11d898d8224643d2a7fd1e069e9 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 17 Oct 2018 15:08:48 +0100 Subject: [PATCH] import json in EVAL_TEMPLATE and json parse response from eval api --- modules/eval_python.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/eval_python.py b/modules/eval_python.py index a5c4de5a..1b92b403 100644 --- a/modules/eval_python.py +++ b/modules/eval_python.py @@ -2,7 +2,7 @@ import html, socket from src import ModuleManager, utils EVAL_TEMPLATE = """ -import io, sys +import io, json, sys compiled = compile(sys.stdin.read(), "code", "single") @@ -43,7 +43,10 @@ class Module(ModuleManager.BaseModule): if page: out = page.split("
", 1)[1].strip("\n") out = html.unescape(out) - event["stdout"].write("%s: %s" % (event["user"].nickname, out)) + out = json.loads(out) + + event["stdout" if out["success"] else "stderr"].write( + "%s: %s" % (event["user"].nickname, out)) else: event["stderr"].write("%s: failed to eval" % event["user"].nickname)