Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
37ca6bf7
Commit
37ca6bf7
authored
Feb 14, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move our specialization of safe_exec into a new module to avoid circular imports.
parent
6297d645
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
55 deletions
+30
-55
common/lib/capa/capa/capa_problem.py
+2
-52
common/lib/capa/capa/responsetypes.py
+8
-3
common/lib/capa/capa/safe_exec.py
+20
-0
No files found.
common/lib/capa/capa/capa_problem.py
View file @
37ca6bf7
...
...
@@ -13,8 +13,6 @@ Main module which shows problems (of "capa" type).
This is used by capa_module.
'''
from
__future__
import
division
from
datetime
import
datetime
import
logging
import
math
...
...
@@ -29,17 +27,6 @@ from lxml import etree
from
xml.sax.saxutils
import
unescape
from
copy
import
deepcopy
<<<<<<<
HEAD
import
chem
import
chem.miller
import
chem.chemcalc
import
chem.chemtools
import
verifiers
import
verifiers.draganddrop
import
calc
=======
>>>>>>>
Work
in
progress
to
sandbox
the
uses
of
eval
in
LMS
.
from
.correctmap
import
CorrectMap
import
inputtypes
import
customrender
...
...
@@ -48,8 +35,7 @@ import xqueue_interface
# to be replaced with auto-registering
import
responsetypes
from
codejail.safe_exec
import
safe_exec
import
safe_exec
# dict of tagname, Response Class -- this should come from auto-registering
response_tag_dict
=
dict
([(
x
.
response_tag
,
x
)
for
x
in
responsetypes
.
__all__
])
...
...
@@ -66,32 +52,6 @@ html_transforms = {'problem': {'tag': 'div'},
"math"
:
{
'tag'
:
'span'
},
}
<<<<<<<
HEAD
global_context
=
{
'random'
:
random
,
'numpy'
:
numpy
,
'math'
:
math
,
'scipy'
:
scipy
,
'calc'
:
calc
,
'eia'
:
eia
,
'chemcalc'
:
chem
.
chemcalc
,
'chemtools'
:
chem
.
chemtools
,
'miller'
:
chem
.
miller
,
'draganddrop'
:
verifiers
.
draganddrop
}
=======
safe_exec_assumed_imports
=
[
"random"
,
"numpy"
,
"math"
,
"scipy"
,
"calc"
,
"eia"
,
(
"chemcalc"
,
"chem.chemcalc"
),
(
"chemtools"
,
"chem.chemtools"
),
(
"miller"
,
"chem.miller"
),
(
"draganddrop"
,
"verifiers.draganddrop"
),
]
>>>>>>>
Work
in
progress
to
sandbox
the
uses
of
eval
in
LMS
.
# These should be removed from HTML output, including all subelements
html_problem_semantics
=
[
"codeparam"
,
"responseparam"
,
"answer"
,
"script"
,
"hintgroup"
,
"openendedparam"
,
"openendedrubric"
]
...
...
@@ -479,16 +439,6 @@ class LoncapaProblem(object):
'''
random
.
seed
(
self
.
seed
)
# TODO: REMOVE THIS COMMENTED OUT CODE.
## save global context in here also
#context = {'global_context': global_context}
#
## initialize context to have stuff in global_context
#context.update(global_context)
#
# put globals there also
#context['__builtins__'] = globals()['__builtins__']
context
=
{}
# pass instance of LoncapaProblem in
...
...
@@ -523,7 +473,7 @@ class LoncapaProblem(object):
context
[
'script_code'
]
+=
code
try
:
# use "context" for global context; thus defs in code are global within code
safe_exec
(
code
,
context
,
future_division
=
True
,
assumed_imports
=
safe_exec_assumed_imports
)
safe_exec
.
safe_exec
(
code
,
context
)
except
Exception
as
err
:
log
.
exception
(
"Error while execing script code: "
+
code
)
msg
=
"Error while executing script code:
%
s"
%
str
(
err
)
.
replace
(
'<'
,
'<'
)
...
...
common/lib/capa/capa/responsetypes.py
View file @
37ca6bf7
...
...
@@ -37,7 +37,7 @@ from lxml import etree
from
lxml.html.soupparser
import
fromstring
as
fromstring_bs
# uses Beautiful Soup!!! FIXME?
import
xqueue_interface
from
codejail.safe_exec
import
safe_exec
import
safe_exec
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -971,6 +971,11 @@ def sympy_check2():
if
cfn
:
log
.
debug
(
"cfn =
%
s"
%
cfn
)
# This is a bit twisty. We used to grab the cfn function from
# the context, but now that we sandbox Python execution, we
# can't get functions from previous executions. So we make an
# actual function that will re-execute the original script,
# and invoke the function with the data needed.
def
make_check_function
(
script_code
,
cfn
):
def
check_function
(
expect
,
ans
):
code
=
(
script_code
+
"
\n
"
+
...
...
@@ -979,7 +984,7 @@ def sympy_check2():
'expect'
:
expect
,
'ans'
:
ans
,
}
safe_exec
(
code
,
globals_dict
)
safe_exec
.
safe_exec
(
code
,
globals_dict
)
return
globals_dict
[
'cfn_return'
]
return
check_function
...
...
@@ -1924,7 +1929,7 @@ class SchematicResponse(LoncapaResponse):
json
.
loads
(
student_answers
[
k
])
for
k
in
sorted
(
self
.
answer_ids
)
]
self
.
context
.
update
({
'submission'
:
submission
})
safe_exec
(
self
.
code
,
{},
self
.
context
)
safe_exec
.
safe_exec
(
self
.
code
,
{},
self
.
context
)
cmap
=
CorrectMap
()
cmap
.
set_dict
(
dict
(
zip
(
sorted
(
self
.
answer_ids
),
self
.
context
[
'correct'
])))
...
...
common/lib/capa/capa/safe_exec.py
0 → 100644
View file @
37ca6bf7
"""Capa's specialized use of codejail.safe_exec."""
import
codejail.safe_exec
def
safe_exec
(
code
,
globals_dict
,
locals_dict
=
None
):
codejail
.
safe_exec
.
safe_exec
(
code
,
globals_dict
,
locals_dict
,
future_division
=
True
,
assumed_imports
=
[
"random"
,
"numpy"
,
"math"
,
"scipy"
,
"calc"
,
"eia"
,
(
"chemcalc"
,
"chem.chemcalc"
),
(
"chemtools"
,
"chem.chemtools"
),
(
"miller"
,
"chem.miller"
),
(
"draganddrop"
,
"verifiers.draganddrop"
),
],
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment