Support py2 and py3 in eval_python
This commit is contained in:
parent
b2dd75d68f
commit
b884b0e170
1 changed files with 32 additions and 25 deletions
|
@ -1,38 +1,45 @@
|
||||||
import socket
|
import socket
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
EVAL_URL = "https://pyeval.appspot.com/exec"
|
EVAL_TEMPLATE = """
|
||||||
|
import sys
|
||||||
|
result = eval(sys.stdin.read())
|
||||||
|
if not result == None:
|
||||||
|
sys.stdout.write(str(result))
|
||||||
|
"""
|
||||||
|
|
||||||
|
EVAL_URL = "https://tpcg.tutorialspoint.com/tpcg.php"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Python"
|
_name = "Python"
|
||||||
@utils.hook("received.command.py", alias_of="python")
|
|
||||||
@utils.hook("received.command.python", min_args=1)
|
def _eval(self, lang, event):
|
||||||
def eval(self, event):
|
|
||||||
"""
|
|
||||||
:help: Evaluate a python statement
|
|
||||||
:usage: <statement>
|
|
||||||
"""
|
|
||||||
id = None
|
|
||||||
try:
|
try:
|
||||||
id = utils.http.get_url(EVAL_URL,
|
page = utils.http.get_url(EVAL_URL,
|
||||||
post_data={"input": event["args"]},
|
post_data={
|
||||||
|
"lang": lang,
|
||||||
|
"code": EVAL_TEMPLATE,
|
||||||
|
"execute": "%s main.py" % lang,
|
||||||
|
"mainfile": "main.py",
|
||||||
|
"stdinput": event["args"]
|
||||||
|
},
|
||||||
method="POST")
|
method="POST")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not id == None:
|
if page:
|
||||||
try:
|
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
||||||
page = utils.http.get_url(EVAL_URL,
|
page.split("</b></span><br>", 1)[1]))
|
||||||
get_params={"id": id},
|
else:
|
||||||
json=True)
|
event["stderr"].write("%s: failed to eval" % event["user"].nickname)
|
||||||
except socket.timeout:
|
|
||||||
event["stderr"].write("%s: eval timed out" %
|
|
||||||
event["user"].nickname)
|
|
||||||
return
|
|
||||||
|
|
||||||
if page:
|
@utils.hook("received.command.py2", alias_of="python2")
|
||||||
event["stdout"].write("%s: %s" % (event["user"].nickname,
|
@utils.hook("received.command.python2", min_args=1)
|
||||||
page["output"].strip("\n")))
|
def eval(self, event):
|
||||||
return
|
self._eval("python", event)
|
||||||
|
|
||||||
event["stderr"].write("%s: failed to eval" % event["user"].nickname)
|
@utils.hook("received.command.py", alias_of="python")
|
||||||
|
@utils.hook("received.command.py3", alias_of="python")
|
||||||
|
@utils.hook("received.command.python", alias_of="python3")
|
||||||
|
@utils.hook("received.command.python3", min_args=1)
|
||||||
|
def eval3(self, event):
|
||||||
|
self._eval("python3", event)
|
||||||
|
|
Loading…
Reference in a new issue