* simplify logic--tracker just tracks errors. Trackers should not raise,
and are not be responsible for logging.
* adapted code to use trackers.
* Started cleanup of error handling code:
- if need to add info and re-raise, just do that. No logging.
- if working around a problem, log and track as needed.
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from lxml import etree
|
|
from xmodule.editing_module import EditingDescriptor
|
|
from xmodule.xml_module import XmlDescriptor
|
|
import logging
|
|
import sys
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
class RawDescriptor(XmlDescriptor, EditingDescriptor):
|
|
"""
|
|
Module that provides a raw editing view of its data and children. It
|
|
requires that the definition xml is valid.
|
|
"""
|
|
@classmethod
|
|
def definition_from_xml(cls, xml_object, system):
|
|
return {'data': etree.tostring(xml_object)}
|
|
|
|
def definition_to_xml(self, resource_fs):
|
|
try:
|
|
return etree.fromstring(self.definition['data'])
|
|
except etree.XMLSyntaxError as err:
|
|
# Can't recover here, so just add some info and
|
|
# re-raise
|
|
lines = self.definition['data'].split('\n')
|
|
line, offset = err.position
|
|
msg = ("Unable to create xml for problem {loc}. "
|
|
"Context: '{context}'".format(
|
|
context=lines[line - 1][offset - 40:offset + 40],
|
|
loc=self.location))
|
|
raise Exception, msg, sys.exc_info()[2]
|