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
d750d945
Commit
d750d945
authored
Jul 30, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove malformed tags when contents aren't malformed anymore.
parent
c53ed6a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
7 deletions
+49
-7
common/lib/xmodule/tests/test_import.py
+25
-1
common/lib/xmodule/xmodule/malformed_module.py
+24
-6
No files found.
common/lib/xmodule/tests/test_import.py
View file @
d750d945
from
path
import
path
from
path
import
path
import
unittest
import
unittest
from
lxml
import
etree
from
xmodule.x_module
import
XMLParsingSystem
,
XModuleDescriptor
from
xmodule.x_module
import
XMLParsingSystem
,
XModuleDescriptor
from
xmodule.errorhandlers
import
ignore_errors_handler
from
xmodule.errorhandlers
import
ignore_errors_handler
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
...
@@ -61,3 +62,26 @@ class ImportTestCase(unittest.TestCase):
...
@@ -61,3 +62,26 @@ class ImportTestCase(unittest.TestCase):
self
.
assertEqual
(
descriptor
.
definition
[
'data'
],
self
.
assertEqual
(
descriptor
.
definition
[
'data'
],
re_import_descriptor
.
definition
[
'data'
])
re_import_descriptor
.
definition
[
'data'
])
def
test_fixed_xml_tag
(
self
):
"""Make sure a tag that's been fixed exports as the original tag type"""
# create a malformed tag with valid xml contents
root
=
etree
.
Element
(
'malformed'
)
good_xml
=
'''<sequential display_name="fixed"><video url="hi"/></sequential>'''
root
.
text
=
good_xml
xml_str_in
=
etree
.
tostring
(
root
)
# load it
system
=
self
.
get_system
()
descriptor
=
XModuleDescriptor
.
load_from_xml
(
xml_str_in
,
system
,
'org'
,
'course'
,
None
)
# export it
resource_fs
=
None
xml_str_out
=
descriptor
.
export_to_xml
(
resource_fs
)
# Now make sure the exported xml is a sequential
xml_out
=
etree
.
fromstring
(
xml_str_out
)
self
.
assertEqual
(
xml_out
.
tag
,
'sequential'
)
common/lib/xmodule/xmodule/malformed_module.py
View file @
d750d945
from
pkg_resources
import
resource_string
from
pkg_resources
import
resource_string
from
lxml
import
etree
from
lxml
import
etree
from
xmodule.x_module
import
XModule
from
xmodule.mako_module
import
MakoModuleDescriptor
from
xmodule.mako_module
import
MakoModuleDescriptor
from
xmodule.xml_module
import
XmlDescriptor
from
xmodule.xml_module
import
XmlDescriptor
from
xmodule.editing_module
import
EditingDescriptor
from
xmodule.editing_module
import
EditingDescriptor
...
@@ -8,10 +9,18 @@ import logging
...
@@ -8,10 +9,18 @@ import logging
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
class
MalformedModule
(
XModule
):
def
get_html
(
self
):
'''Show an error.
TODO (vshnayder): proper style, divs, etc.
'''
return
"Malformed content--not showing through get_html()"
class
MalformedDescriptor
(
EditingDescriptor
):
class
MalformedDescriptor
(
EditingDescriptor
):
"""
"""
Module that provides a raw editing view of broken xml.
Module that provides a raw editing view of broken xml.
"""
"""
module_class
=
MalformedModule
@classmethod
@classmethod
def
from_xml
(
cls
,
xml_data
,
system
,
org
=
None
,
course
=
None
):
def
from_xml
(
cls
,
xml_data
,
system
,
org
=
None
,
course
=
None
):
...
@@ -20,8 +29,8 @@ class MalformedDescriptor(EditingDescriptor):
...
@@ -20,8 +29,8 @@ class MalformedDescriptor(EditingDescriptor):
Does not try to parse the data--just stores it.
Does not try to parse the data--just stores it.
'''
'''
#log.debug("processing '{0}'".format(xml_data))
try
:
try
:
# If this is already a malformed tag, don't want to re-wrap it.
xml_obj
=
etree
.
fromstring
(
xml_data
)
xml_obj
=
etree
.
fromstring
(
xml_data
)
if
xml_obj
.
tag
==
'malformed'
:
if
xml_obj
.
tag
==
'malformed'
:
xml_data
=
xml_obj
.
text
xml_data
=
xml_obj
.
text
...
@@ -40,9 +49,18 @@ class MalformedDescriptor(EditingDescriptor):
...
@@ -40,9 +49,18 @@ class MalformedDescriptor(EditingDescriptor):
def
export_to_xml
(
self
,
resource_fs
):
def
export_to_xml
(
self
,
resource_fs
):
'''
'''
Export as a string wrapped in xml
If the definition data is invalid xml, export it wrapped in a malformed
'''
tag. If it is valid, export without the wrapper.
root
=
etree
.
Element
(
'malformed'
)
root
.
text
=
self
.
definition
[
'data'
]
return
etree
.
tostring
(
root
)
NOTE: There may still be problems with the valid xml--it could be
missing required attributes, could have the wrong tags, refer to missing
files, etc.
'''
try
:
xml
=
etree
.
fromstring
(
self
.
definition
[
'data'
])
return
etree
.
tostring
(
xml
)
except
etree
.
XMLSyntaxError
:
# still not valid.
root
=
etree
.
Element
(
'malformed'
)
root
.
text
=
self
.
definition
[
'data'
]
return
etree
.
tostring
(
root
)
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