Commit 95699849 by Ned Batchelder

Pass safe_exec a slug, the problem or response id; Use the latest CodeJail, with slug support.

parent 0714b975
...@@ -469,6 +469,7 @@ class LoncapaProblem(object): ...@@ -469,6 +469,7 @@ class LoncapaProblem(object):
random_seed=self.seed, random_seed=self.seed,
python_path=python_path, python_path=python_path,
cache=self.system.cache, cache=self.system.cache,
slug=self.problem_id,
) )
except Exception as err: except Exception as err:
log.exception("Error while execing script code: " + all_code) log.exception("Error while execing script code: " + all_code)
......
...@@ -288,7 +288,7 @@ class LoncapaResponse(object): ...@@ -288,7 +288,7 @@ class LoncapaResponse(object):
} }
try: try:
safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path']) safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path'], slug=self.id)
except Exception as err: except Exception as err:
msg = 'Error %s in evaluating hint function %s' % (err, hintfn) msg = 'Error %s in evaluating hint function %s' % (err, hintfn)
msg += "\nSee XML source line %s" % getattr( msg += "\nSee XML source line %s" % getattr(
...@@ -973,7 +973,7 @@ class CustomResponse(LoncapaResponse): ...@@ -973,7 +973,7 @@ class CustomResponse(LoncapaResponse):
'ans': ans, 'ans': ans,
} }
globals_dict.update(kwargs) globals_dict.update(kwargs)
safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path']) safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path'], slug=self.id)
return globals_dict['cfn_return'] return globals_dict['cfn_return']
return check_function return check_function
...@@ -1090,7 +1090,7 @@ class CustomResponse(LoncapaResponse): ...@@ -1090,7 +1090,7 @@ class CustomResponse(LoncapaResponse):
# exec the check function # exec the check function
if isinstance(self.code, basestring): if isinstance(self.code, basestring):
try: try:
safe_exec.safe_exec(self.code, self.context, cache=self.system.cache) safe_exec.safe_exec(self.code, self.context, cache=self.system.cache, slug=self.id)
except Exception as err: except Exception as err:
self._handle_exec_exception(err) self._handle_exec_exception(err)
...@@ -1814,7 +1814,7 @@ class SchematicResponse(LoncapaResponse): ...@@ -1814,7 +1814,7 @@ class SchematicResponse(LoncapaResponse):
] ]
self.context.update({'submission': submission}) self.context.update({'submission': submission})
try: try:
safe_exec.safe_exec(self.code, self.context, cache=self.system.cache) safe_exec.safe_exec(self.code, self.context, cache=self.system.cache, slug=self.id)
except Exception as err: except Exception as err:
msg = 'Error %s in evaluating SchematicResponse' % err msg = 'Error %s in evaluating SchematicResponse' % err
raise ResponseError(msg) raise ResponseError(msg)
......
...@@ -71,7 +71,7 @@ def update_hash(hasher, obj): ...@@ -71,7 +71,7 @@ def update_hash(hasher, obj):
@statsd.timed('capa.safe_exec.time') @statsd.timed('capa.safe_exec.time')
def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None): def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None, slug=None):
""" """
Execute python code safely. Execute python code safely.
...@@ -87,6 +87,9 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None ...@@ -87,6 +87,9 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None
to cache the execution, taking into account the code, the values of the globals, to cache the execution, taking into account the code, the values of the globals,
and the random seed. and the random seed.
`slug` is an arbitrary string, a description that's meaningful to the
caller, that will be used in log messages.
""" """
# Check the cache for a previous result. # Check the cache for a previous result.
if cache: if cache:
...@@ -112,7 +115,7 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None ...@@ -112,7 +115,7 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None
try: try:
codejail_safe_exec( codejail_safe_exec(
code_prolog + LAZY_IMPORTS + code, globals_dict, code_prolog + LAZY_IMPORTS + code, globals_dict,
python_path=python_path, python_path=python_path, slug=slug,
) )
except SafeExecException as e: except SafeExecException as e:
emsg = e.message emsg = e.message
......
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
# Our libraries: # Our libraries:
-e git+https://github.com/edx/XBlock.git@2144a25d#egg=XBlock -e git+https://github.com/edx/XBlock.git@2144a25d#egg=XBlock
-e git+https://github.com/edx/codejail.git@874361f#egg=codejail -e git+https://github.com/edx/codejail.git@cf83d6a#egg=codejail
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment