from django.http import HttpResponse from pypy.translator.sandbox import pypy_interact from cStringIO import StringIO SANDBOX_BIN = 'pypy-sandbox' def codepad(request): if request.method == 'POST': code = request.POST['codepad'] code_output = StringIO() sandproc = pypy_interact.PyPySandboxedProc(SANDBOX_BIN, ['-c', code]) try: sandproc.interact(stdout=code_output, stderr=code_output) finally: sandproc.kill() page = """
Code
%s
Output
%s
""" % (code, code_output.getvalue()) else: page = """
""" return HttpResponse(page)