2010-01-17 04:24:36 +00:00
|
|
|
import re
|
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
from util import hook, http
|
2010-01-17 04:24:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
re_lineends = re.compile(r'[\r\n]*')
|
|
|
|
|
|
|
|
|
|
|
|
@hook.command
|
2010-05-07 23:16:44 +00:00
|
|
|
def python(inp):
|
|
|
|
".python <prog> -- executes python code <prog>"
|
2010-01-17 04:24:36 +00:00
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
res = http.get("http://eval.appspot.com/eval", statement=inp).splitlines()
|
|
|
|
|
2010-01-17 04:24:36 +00:00
|
|
|
if len(res) == 0:
|
|
|
|
return
|
|
|
|
res[0] = re_lineends.split(res[0])[0]
|
|
|
|
if not res[0] == 'Traceback (most recent call last):':
|
2010-04-23 03:47:41 +00:00
|
|
|
return res[0].decode('utf8', 'ignore')
|
2010-01-17 04:24:36 +00:00
|
|
|
else:
|
2010-04-23 03:47:41 +00:00
|
|
|
return res[-1].decode('utf8', 'ignore')
|