File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments