Use a more reliable API for evaling python
This commit is contained in:
parent
d460375629
commit
b2dd75d68f
1 changed files with 23 additions and 13 deletions
|
@ -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"]},
|
||||||
except socket.timeout:
|
method="POST")
|
||||||
event["stderr"].write("%s: eval timed out" %
|
except:
|
||||||
event["user"].nickname)
|
pass
|
||||||
return
|
|
||||||
|
|
||||||
if not page == None and code == 200:
|
if not id == None:
|
||||||
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
try:
|
||||||
page))
|
page = utils.http.get_url(EVAL_URL,
|
||||||
else:
|
get_params={"id": id},
|
||||||
event["stderr"].write("%s: failed to eval" %
|
json=True)
|
||||||
event["user"].nickname)
|
except socket.timeout:
|
||||||
|
event["stderr"].write("%s: eval timed out" %
|
||||||
|
event["user"].nickname)
|
||||||
|
return
|
||||||
|
|
||||||
|
if page:
|
||||||
|
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
||||||
|
page["output"].strip("\n")))
|
||||||
|
return
|
||||||
|
|
||||||
|
event["stderr"].write("%s: failed to eval" % event["user"].nickname)
|
||||||
|
|
Loading…
Reference in a new issue