diff options
author | Prabhu Ramachandran | 2016-10-04 15:44:05 +0530 |
---|---|---|
committer | GitHub | 2016-10-04 15:44:05 +0530 |
commit | 91dd42214ba5ad88c5158b50a7746caa3841a883 (patch) | |
tree | 188f8aa284783e844eccffe350839d6a18f4da8b /yaksh/python_stdio_evaluator.py | |
parent | 6b08e56fe3cf70ffbcbd1ed432dde25babe48148 (diff) | |
parent | 59fa975a9fd0f6728cf62b1069abecac95a77b68 (diff) | |
download | online_test-91dd42214ba5ad88c5158b50a7746caa3841a883.tar.gz online_test-91dd42214ba5ad88c5158b50a7746caa3841a883.tar.bz2 online_test-91dd42214ba5ad88c5158b50a7746caa3841a883.zip |
Merge pull request #143 from adityacp/python2to3-migrate
Migration Python 2 to 3
Diffstat (limited to 'yaksh/python_stdio_evaluator.py')
-rw-r--r-- | yaksh/python_stdio_evaluator.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 2cfd9c8..cbbbfd6 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -1,16 +1,23 @@ #!/usr/bin/env python +from __future__ import unicode_literals import sys import traceback import os from os.path import join import importlib from contextlib import contextmanager -from ast import literal_eval -# local imports -from code_evaluator import CodeEvaluator -from StringIO import StringIO -from file_utils import copy_files, delete_files from textwrap import dedent + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + +# Local imports +from .code_evaluator import CodeEvaluator +from .file_utils import copy_files, delete_files + + @contextmanager def redirect_stdout(): new_target = StringIO() @@ -25,10 +32,10 @@ class PythonStdioEvaluator(CodeEvaluator): """Tests the Python code obtained from Code Server""" def teardown(self): - super(PythonStdioEvaluator, self).teardown() # Delete the created file. if self.files: delete_files(self.files) + super(PythonStdioEvaluator, self).teardown() def compile_code(self, user_answer, file_paths, expected_input, expected_output): @@ -43,7 +50,7 @@ class PythonStdioEvaluator(CodeEvaluator): sys.stdin = input_buffer with redirect_stdout() as output_buffer: exec_scope = {} - exec submitted in exec_scope + exec(submitted, exec_scope) self.output_value = output_buffer.getvalue().rstrip("\n") return self.output_value |