Added (working) first version of new python thingy

This commit is contained in:
Luke Rogers 2012-08-28 16:51:26 +12:00
parent 2871bd3211
commit 30f1c18d94
3 changed files with 33 additions and 18 deletions

View file

@ -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)