diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/python_session.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/server/python_session.py b/server/python_session.py index 4c4a781..011adc3 100644 --- a/server/python_session.py +++ b/server/python_session.py @@ -1,7 +1,9 @@ # coding=utf-8 +import ast import multiprocessing.managers import threading + import server.user_session from db.models import Problem from . import problems @@ -67,6 +69,13 @@ class PythonSession(object): language, problem_group, problem = Problem.get_identifier(problem_id) problem_module = problems.load_problem(language, problem_group, problem, 'common') + # Check syntax. + try: + tree = ast.parse(program, filename='user') + except SyntaxError as ex: + error_msg = '{}{}^\n{}'.format(ex.text, ' '*(ex.offset-1), ex.msg) + return [{'id': 'syntax_error', 'args': {'lineno': ex.lineno, 'message': error_msg}}] + # Try problem-specific hints. if hasattr(problem_module, 'hint'): hints = problem_module.hint(session, program) |