8 from xml.etree.ElementTree
import ElementTree
13 xmlString = etree.tostring(rootXml, pretty_print=
True)
15 xmlString =
'<?xml version="1.0"?>\n' + xmlString
20 return dict((key, obj[key])
for key
in keys)
27 return etree.SubElement(doc, sub)
28 elif isinstance(sub, etree._Element):
32 raise Exception(
'Invalid sub value')
36 return str(x).rstrip(
'.')
40 children = node.getchildren()
43 return not isinstance(node, etree._Comment)
44 return list(filter(predicate, children))
49 return isinstance(obj, basestring)
51 return isinstance(obj, str)
55 """ Simplify yaml representation for pretty printing """ 61 elif type(obj)
in [int, float, bool]:
63 elif hasattr(obj,
'to_yaml'):
65 elif isinstance(obj, etree._Element):
66 out = etree.tostring(obj, pretty_print=
True)
67 elif type(obj) == dict:
69 for (var, value)
in obj.items():
71 elif hasattr(obj,
'tolist'):
74 elif isinstance(obj, collections.Iterable):
75 out = [
to_yaml(item)
for item
in obj]
83 return list(vars(self).keys())
88 raw = dict((var, getattr(self, var))
for var
in self.
get_refl_vars())
93 return yaml.dump(self.
to_yaml()).rstrip()
def xml_string(rootXml, addHeader=True)