|
| 1 | +#!/usr/bin/python2.5 |
| 2 | + |
| 3 | +# Online Python Tutor |
| 4 | +# Copyright (C) 2010 Philip J. Guo (philip@pgbovine.net) |
| 5 | +# https://github.com/pgbovine/OnlinePythonTutor/ |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | + |
| 21 | +# Load a question file in the '../questions/' sub-directory, parse it, |
| 22 | +# and return it to the caller in JSON format |
| 23 | +QUESTIONS_DIR = '../questions/' |
| 24 | + |
| 25 | +from parse_questions import parseQuestionsFile |
| 26 | + |
| 27 | +import cgi, os |
| 28 | + |
| 29 | +form = cgi.FieldStorage() |
| 30 | +question_file = form['question_file'].value |
| 31 | + |
| 32 | +fn = QUESTIONS_DIR + question_file |
| 33 | +assert os.path.isfile(fn) |
| 34 | + |
| 35 | +output_json = demjson.encode(parseQuestionsFile(fn), compactly=False) |
| 36 | + |
| 37 | + |
| 38 | +# Crucial first line to make sure that Apache serves this data |
| 39 | +# correctly - DON'T FORGET THE EXTRA NEWLINES!!!: |
| 40 | +print "Content-type: text/plain; charset=iso-8859-1\n\n" |
| 41 | +print output_json |
0 commit comments