Use a more reliable API for evaling python

This commit is contained in:
jesopo 2018-10-12 11:56:13 +01:00
parent d460375629
commit b2dd75d68f

View file

@ -1,7 +1,7 @@
import socket import socket
from src import ModuleManager, utils from src import ModuleManager, utils
EVAL_URL = "https://eval.appspot.com/eval" EVAL_URL = "https://pyeval.appspot.com/exec"
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
_name = "Python" _name = "Python"
@ -12,17 +12,27 @@ class Module(ModuleManager.BaseModule):
:help: Evaluate a python statement :help: Evaluate a python statement
:usage: <statement> :usage: <statement>
""" """
id = None
try: try:
code, page = utils.http.get_url(EVAL_URL, get_params={ id = utils.http.get_url(EVAL_URL,
"statement": event["args"]}, code=True) post_data={"input": event["args"]},
method="POST")
except:
pass
if not id == None:
try:
page = utils.http.get_url(EVAL_URL,
get_params={"id": id},
json=True)
except socket.timeout: except socket.timeout:
event["stderr"].write("%s: eval timed out" % event["stderr"].write("%s: eval timed out" %
event["user"].nickname) event["user"].nickname)
return return
if not page == None and code == 200: if page:
event["stdout"].write("%s: %s" % (event["user"].nickname, event["stdout"].write("%s: %s" % (event["user"].nickname,
page)) page["output"].strip("\n")))
else: return
event["stderr"].write("%s: failed to eval" %
event["user"].nickname) event["stderr"].write("%s: failed to eval" % event["user"].nickname)