the user successfully answered the question that depended on it (“What
is your quest?”).
-Quizzer requires Python ≥ 3.3. If Pygments is installed, the command
+Quizzer requires Python ≥ 3.2. If Pygments is installed, the command
line prompt will be colored.
Types of questions:
temporary directories, and we judge success by comparing the output
of the teardown phase (and optionally the output of the answer
phase). You can optionally set a timeout to catch answers that
- hang. There is no sandboxing (other than working in a scratch
- directory), so it's not a good idea to serve questions like this on
- a public interface (stick to ``cli``).
+ hang, although this requires Python ≥ 3.3. There is no sandboxing
+ (other than working in a scratch directory), so it's not a good idea
+ to serve questions like this on a public interface (stick to
+ ``cli``).
import logging as _logging
import os.path as _os_path
import subprocess as _subprocess
+import sys as _sys
import tempfile as _tempfile
from . import error as _error
+LOG = _logging.getLogger(__name__)
+
+
def invoke(args, stdin=None, stdout=_subprocess.PIPE, stderr=_subprocess.PIPE,
universal_newlines=False, timeout=None, expect=None, **kwargs):
if stdin:
universal_newlines=universal_newlines, **kwargs)
except FileNotFoundError as e:
raise _error.CommandError(arguments=args, stdin=stdin) from e
- try:
- stdout,stderr = p.communicate(input=stdin, timeout=timeout)
- except _subprocess.TimeoutExpired as e:
- p.kill()
- stdout,stderr = p.communicate()
- status = p.wait()
- raise _error.CommandError(
- msg='timeout ({}s) expired'.format(timeout),
- arguments=args, stdin=stdin, stdout=stdout, stderr=stderr,
- status=status) from e
+ if _sys.version_info >= (3, 3): # Python >= 3.3
+ try:
+ stdout,stderr = p.communicate(input=stdin, timeout=timeout)
+ except _subprocess.TimeoutExpired as e:
+ p.kill()
+ stdout,stderr = p.communicate()
+ status = p.wait()
+ raise _error.CommandError(
+ msg='timeout ({}s) expired'.format(timeout),
+ arguments=args, stdin=stdin, stdout=stdout, stderr=stderr,
+ status=status) from e
+ else: # Python <= 3.2 don't support communicate(..., timeout)
+ if timeout is not None:
+ LOG.warning('Python version {} does not support timeouts'.format(
+ _sys.version.split()[0]))
+ stdout,stderr = p.communicate(input=stdin)
status = p.wait()
if expect and status not in expect:
raise _error.CommandError(
'Operating System :: OS Independent',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Topic :: Education',
'Topic :: Education :: Computer Aided Instruction (CAI)',