Added early untested version of new python exec code - this probably will not work.
This commit is contained in:
parent
bc847f3fb8
commit
3fa8d5d312
2 changed files with 34 additions and 18 deletions
28
plugins/util/exec.py
Normal file
28
plugins/util/exec.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import http
|
||||
import json, urllib2, sys
|
||||
|
||||
|
||||
def haste(data):
|
||||
URL = "http://paste.dmptr.com"
|
||||
request = urllib2.Request(URL + "/documents", data)
|
||||
response = urllib2.urlopen(request)
|
||||
return("%s/%s" % (URL, json.loads(response.read())['key']))
|
||||
|
||||
|
||||
def execute_eval(code, paste_multiline=True):
|
||||
while True:
|
||||
output = http.get("http://eval.appspot.com/eval", statement=code).rstrip('\n')
|
||||
if output:
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
||||
if "Traceback (most recent call last):" in output:
|
||||
status = "Python error: "
|
||||
else:
|
||||
status = "Code executed sucessfully: "
|
||||
|
||||
if "\n" in output and paste_multiline:
|
||||
return status + haste(output)
|
||||
else:
|
||||
return output
|
Reference in a new issue