Skip to content

Commit b20bf05

Browse files
author
Philip Guo
committed
generic CGI executor
1 parent 67e1b64 commit b20bf05

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

PyTutorGAE/web_exec.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# <INSERT YOUR VERSION OF PYTHON HERE AS A #! LINE>
2+
3+
# Minimal CGI script for Online Python Tutor (v3).
4+
5+
import cgi
6+
import json
7+
import pg_logger
8+
import sys
9+
10+
11+
def cgi_finalizer(input_code, output_trace):
12+
"""Write JSON output for js/pytutor.js as a CGI result."""
13+
ret = dict(code=input_code, trace=output_trace)
14+
json_output = json.dumps(ret, indent=None) # use indent=None for most compact repr
15+
print("Content-type: text/plain; charset=iso-8859-1\n")
16+
print(json_output)
17+
18+
19+
if len(sys.argv) > 1:
20+
user_script = open(sys.argv[1]).read()
21+
else:
22+
form = cgi.FieldStorage()
23+
user_script = form['user_script'].value
24+
25+
pg_logger.exec_script_str(user_script, cgi_finalizer)

0 commit comments

Comments
 (0)