Commit 50bea28d by Chris Dodge

Add a 'string literal' serialization method and use it in the lambda function…

Add a 'string literal' serialization method and use it in the lambda function mapping table when the value to xml serialize is of basestring type. Also a couple of drive-by pep8 fixes.
parent b7eb287a
......@@ -88,6 +88,16 @@ def serialize_field(value):
return json.dumps(value, cls=EdxJSONEncoder)
def serialize_string_literal(value):
"""
Assert that the value is a base string and - if it is - simply return it
"""
if not isinstance(value, basestring):
raise Exception('Value {0} is not of type basestring!'.format(value))
return value
def deserialize_field(field, value):
"""
Deserialize the string version to the value stored internally.
......@@ -166,7 +176,7 @@ class XmlDescriptor(XModuleDescriptor):
for field in set(cls.fields + cls.lms.fields):
if field.name == attr:
from_xml = lambda val: deserialize_field(field, val)
to_xml = lambda val : serialize_field(val)
to_xml = lambda val: serialize_string_literal(val) if isinstance(val, basestring) else serialize_field(val)
return AttrMap(from_xml, to_xml)
return AttrMap()
......@@ -254,7 +264,7 @@ class XmlDescriptor(XModuleDescriptor):
definition, children = cls.definition_from_xml(definition_xml, system)
if definition_metadata:
definition['definition_metadata'] = definition_metadata
definition['filename'] = [ filepath, filename ]
definition['filename'] = [filepath, filename]
return definition, children
......@@ -280,7 +290,6 @@ class XmlDescriptor(XModuleDescriptor):
metadata[attr] = attr_map.from_xml(val)
return metadata
@classmethod
def apply_policy(cls, metadata, policy):
"""
......@@ -374,7 +383,6 @@ class XmlDescriptor(XModuleDescriptor):
"""
return True
def export_to_xml(self, resource_fs):
"""
Returns an xml string representing this module, and all modules
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment