Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2013-05-29, with Hotfix 2013-05-30 back into master #6

Merged
merged 12 commits into from
May 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cms/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<div class="wrapper wrapper-view">
<%include file="widgets/header.html" />

## remove this block after advanced settings notification is rewritten
<%block name="view_alerts"></%block>
<div id="page-alert"></div>

<%block name="content"></%block>
Expand All @@ -72,9 +74,13 @@
<%include file="widgets/footer.html" />
<%include file="widgets/tender.html" />

## remove this block after advanced settings notification is rewritten
<%block name="view_notifications"></%block>
<div id="page-notification"></div>
</div>

## remove this block after advanced settings notification is rewritten
<%block name="view_prompts"></%block>
<div id="page-prompt"></div>
<%block name="jsextra"></%block>
</body>
Expand Down
1 change: 1 addition & 0 deletions common/lib/capa/capa/capa_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def _extract_context(self, tree):
random_seed=self.seed,
python_path=python_path,
cache=self.system.cache,
slug=self.problem_id,
)
except Exception as err:
log.exception("Error while execing script code: " + all_code)
Expand Down
15 changes: 8 additions & 7 deletions common/lib/capa/capa/responsetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def __init__(self, xml, inputfields, context, system=None):
self.context = context
self.system = system

self.id = xml.get('id')

for abox in inputfields:
if abox.tag not in self.allowed_inputfields:
msg = "%s: cannot have input field %s" % (
Expand Down Expand Up @@ -286,7 +288,7 @@ def get_hints(self, student_answers, new_cmap, old_cmap):
}

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:
msg = 'Error %s in evaluating hint function %s' % (err, hintfn)
msg += "\nSee XML source line %s" % getattr(
Expand Down Expand Up @@ -935,7 +937,6 @@ def setup_response(self):
# if <customresponse> has an "expect" (or "answer") attribute then save
# that
self.expect = xml.get('expect') or xml.get('answer')
self.myid = xml.get('id')

log.debug('answer_ids=%s' % self.answer_ids)

Expand Down Expand Up @@ -972,7 +973,7 @@ def check_function(expect, ans, **kwargs):
'ans': ans,
}
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 check_function

Expand All @@ -981,7 +982,7 @@ def check_function(expect, ans, **kwargs):
if not self.code:
if answer is None:
log.error("[courseware.capa.responsetypes.customresponse] missing"
" code checking script! id=%s" % self.myid)
" code checking script! id=%s" % self.id)
self.code = ''
else:
answer_src = answer.get('src')
Expand Down Expand Up @@ -1034,7 +1035,7 @@ def get_score(self, student_answers):
# note that this doesn't help the "cfn" version - only the exec version
self.context.update({
# my ID
'response_id': self.myid,
'response_id': self.id,

# expected answer (if given as attribute)
'expect': self.expect,
Expand Down Expand Up @@ -1089,7 +1090,7 @@ def execute_check_function(self, idset, submission):
# exec the check function
if isinstance(self.code, basestring):
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:
self._handle_exec_exception(err)

Expand Down Expand Up @@ -1813,7 +1814,7 @@ def get_score(self, student_answers):
]
self.context.update({'submission': submission})
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:
msg = 'Error %s in evaluating SchematicResponse' % err
raise ResponseError(msg)
Expand Down
7 changes: 5 additions & 2 deletions common/lib/capa/capa/safe_exec/safe_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update_hash(hasher, obj):


@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.

Expand All @@ -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,
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.
if cache:
Expand All @@ -112,7 +115,7 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None
try:
codejail_safe_exec(
code_prolog + LAZY_IMPORTS + code, globals_dict,
python_path=python_path,
python_path=python_path, slug=slug,
)
except SafeExecException as e:
emsg = e.message
Expand Down
Loading