5 from xml.etree
import ElementTree
as ET
6 from xml.dom
import minidom
12 dom = minidom.parseString(ET.tostring(rootXml))
14 lines = dom.toprettyxml(indent=
" ").split(
"\n")
15 if lines
and lines[0].startswith(
"<?xml")
and not addHeader:
18 return "\n".join(filter(
lambda line: line.strip(), lines))
22 return dict((key, obj[key])
for key
in keys)
29 return ET.SubElement(doc, sub)
30 elif isinstance(sub, ET.Element):
34 raise Exception(
'Invalid sub value')
38 return str(x).rstrip(
'.')
47 return isinstance(obj, basestring)
49 return isinstance(obj, str)
53 """ Simplify yaml representation for pretty printing """
59 elif type(obj)
in [int, float, bool]:
61 elif hasattr(obj,
'to_yaml'):
63 elif isinstance(obj, type(ET.Element)):
65 elif type(obj) == dict:
67 for (var, value)
in obj.items():
69 elif hasattr(obj,
'tolist'):
72 elif isinstance(obj, collections.Iterable):
73 out = [
to_yaml(item)
for item
in obj]
81 return list(vars(self).keys())
86 raw = dict((var, getattr(self, var))
for var
in self.
get_refl_vars())
91 return yaml.dump(self.
to_yaml()).rstrip()