Added (working) first version of new python thingy
This commit is contained in:
parent
2871bd3211
commit
30f1c18d94
3 changed files with 33 additions and 18 deletions
|
@ -1,23 +1,10 @@
|
|||
import re
|
||||
|
||||
from util import hook, http
|
||||
|
||||
|
||||
re_lineends = re.compile(r'[\r\n]*')
|
||||
|
||||
from util.execute import eval_py
|
||||
|
||||
@hook.command
|
||||
def python(inp):
|
||||
"python <prog> -- Executes <prog> as Python code."
|
||||
|
||||
inp = inp.replace("~n", "\n")
|
||||
|
||||
res = http.get("http://eval.appspot.com/eval", statement=inp).splitlines()
|
||||
|
||||
if len(res) == 0:
|
||||
return
|
||||
res[0] = re_lineends.split(res[0])[0]
|
||||
if not res[0] == 'Traceback (most recent call last):':
|
||||
return res[0].decode('utf8', 'ignore')
|
||||
else:
|
||||
return res[-1].decode('utf8', 'ignore')
|
||||
return eval_py(inp)
|
||||
|
|
Reference in a new issue