Last active
December 27, 2015 07:19
-
-
Save georgefs/7287978 to your computer and use it in GitHub Desktop.
simple wsgi sandbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urlparse | |
import sys | |
def app(env, start_response): | |
status = '200 OK' | |
start_response(status, []) | |
if env['REQUEST_METHOD'] != 'POST': | |
template = ''' | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script> | |
function exec(){ | |
$('#out').val('') | |
data = $('[name=code]').val(); | |
$.ajax({ | |
url:"", | |
type: "POST", | |
data: {"code": data}, | |
dataType:'text' | |
}).done(function(msg){ | |
$('#out').val(msg) | |
}) | |
} | |
</script> | |
<textarea name="code" rows=20 cols=100> | |
</textarea><br/> | |
<input type="submit" onclick="exec()" readonly><br/> | |
<textarea id="out" rows=20 cols=100> | |
</textarea> | |
''' | |
return [template] | |
else: | |
query = env['wsgi.input'].read() | |
params = urlparse.parse_qs(query) | |
code = params.get('code')[0] | |
out = tempfile.TemporaryFile() | |
sys.stdout = out | |
exec(code) | |
out.seek(0) | |
result = out.read() | |
return [result] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment