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
2d543f10
Commit
2d543f10
authored
Jun 15, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'capa-include' of github.com:MITx/mitx into stable-edx4edx
parents
0dbe63bc
ce74f977
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
common/lib/capa/capa_problem.py
+31
-0
No files found.
common/lib/capa/capa_problem.py
View file @
2d543f10
...
@@ -111,6 +111,7 @@ class LoncapaProblem(object):
...
@@ -111,6 +111,7 @@ class LoncapaProblem(object):
file_text
=
re
.
sub
(
"endouttext
\
s*/"
,
"/text"
,
file_text
)
file_text
=
re
.
sub
(
"endouttext
\
s*/"
,
"/text"
,
file_text
)
self
.
tree
=
etree
.
XML
(
file_text
)
# parse problem XML file into an element tree
self
.
tree
=
etree
.
XML
(
file_text
)
# parse problem XML file into an element tree
self
.
_process_includes
()
# handle any <include file="foo"> tags
# construct script processor context (eg for customresponse problems)
# construct script processor context (eg for customresponse problems)
self
.
context
=
self
.
_extract_context
(
self
.
tree
,
seed
=
self
.
seed
)
self
.
context
=
self
.
_extract_context
(
self
.
tree
,
seed
=
self
.
seed
)
...
@@ -242,6 +243,36 @@ class LoncapaProblem(object):
...
@@ -242,6 +243,36 @@ class LoncapaProblem(object):
# ======= Private Methods Below ========
# ======= Private Methods Below ========
def
_process_includes
(
self
):
'''
Handle any <include file="foo"> tags by reading in the specified file and inserting it
into our XML tree. Fail gracefully if debugging.
'''
includes
=
self
.
tree
.
findall
(
'.//include'
)
for
inc
in
includes
:
file
=
inc
.
get
(
'file'
)
if
file
is
not
None
:
try
:
ifp
=
self
.
system
.
filestore
.
open
(
file
)
# open using I4xSystem OSFS filestore
except
Exception
,
err
:
log
.
error
(
'Error
%
s in problem xml include:
%
s'
%
(
err
,
etree
.
tostring
(
inc
,
pretty_print
=
True
)))
log
.
error
(
'Cannot find file
%
s in
%
s'
%
(
file
,
self
.
system
.
filestore
))
if
not
self
.
system
.
get
(
'DEBUG'
):
# if debugging, don't fail - just log error
raise
else
:
continue
try
:
incxml
=
etree
.
XML
(
ifp
.
read
())
# read in and convert to XML
except
Exception
,
err
:
log
.
error
(
'Error
%
s in problem xml include:
%
s'
%
(
err
,
etree
.
tostring
(
inc
,
pretty_print
=
True
)))
log
.
error
(
'Cannot parse XML in
%
s'
%
(
file
))
if
not
self
.
system
.
get
(
'DEBUG'
):
# if debugging, don't fail - just log error
raise
else
:
continue
parent
=
inc
.
getparent
()
# insert new XML into tree in place of inlcude
parent
.
insert
(
parent
.
index
(
inc
),
incxml
)
parent
.
remove
(
inc
)
log
.
debug
(
'Included
%
s into
%
s'
%
(
file
,
self
.
fileobject
))
def
_extract_context
(
self
,
tree
,
seed
=
struct
.
unpack
(
'i'
,
os
.
urandom
(
4
))[
0
]):
# private
def
_extract_context
(
self
,
tree
,
seed
=
struct
.
unpack
(
'i'
,
os
.
urandom
(
4
))[
0
]):
# private
'''
'''
Extract content of <script>...</script> from the problem.xml file, and exec it in the
Extract content of <script>...</script> from the problem.xml file, and exec it in the
...
...
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