from django.http import HttpResponse import sys sys.path.append('/home/xsx/__usrsrc__/pypy-trunk') from pypy.translator.sandbox import pypy_interact from cStringIO import StringIO SANDBOX_BIN = 'pypy-sandbox' def sandbox(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)