Commit 117cbf46 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Make it possible to serialize as unicode in SEDA export adapter

This is useful in tests because the doctest comparison engine from lxml
works better with text objects. The new _encoding argument is
essentially used a "encoding" argument of lxml's etree.tostring() which
will hence serialize to a unicode string. When doing so, we must also
avoid any XML declaration (otherwise, lxml messes up when loading the
content, not sure why), so we insert the "standalone" flag only when
dumping to bytes.
parent bf353c190352
......@@ -278,10 +278,19 @@ class SEDA2ExportAdapter(EntityAdapter):
return attributes
def dump(self):
"""Return an schema string for the adapted SEDA profile."""
def dump(self, _encoding=None):
"""Return an schema string for the adapted SEDA profile
_encoding will be used as "encoding" argument of lxml's tostring, in
order to retrieve a unicode string. This is useful for tests.
root = self.dump_etree()
return etree.tostring(root, encoding=self.encoding, pretty_print=True, standalone=False)
kwargs = {}
if _encoding is None:
# We only want the XML declaration at all if _encoding is not specified.
kwargs['standalone'] = False
kwargs['encoding'] = _encoding or self.encoding
return etree.tostring(root, pretty_print=True, **kwargs)
def dump_etree(self):
"""Return an XSD etree for the adapted SEDA profile."""
Supports Markdown
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