8 from xml.etree.ElementTree
import ElementTree
12 xmlString = etree.tostring(rootXml, pretty_print =
True)
14 xmlString =
'<?xml version="1.0"?>\n' + xmlString
18 return dict((key, obj[key])
for key
in keys)
24 return etree.SubElement(doc, sub)
25 elif isinstance(sub, etree._Element):
29 raise Exception(
'Invalid sub value')
32 return str(x).rstrip(
'.')
35 children = node.getchildren()
37 return not isinstance(node, etree._Comment)
38 return list(filter(predicate, children))
41 """ Simplify yaml representation for pretty printing """ 44 if obj
is None or type(obj)
in [str, str]:
46 elif type(obj)
in [int, float, bool]:
48 elif hasattr(obj,
'to_yaml'):
50 elif isinstance(obj, etree._Element):
51 out = etree.tostring(obj, pretty_print =
True)
52 elif type(obj) == dict:
54 for (var, value)
in obj.items():
56 elif hasattr(obj,
'tolist'):
59 elif isinstance(obj, collections.Iterable):
60 out = [
to_yaml(item)
for item
in obj]
66 def get_refl_vars(self):
67 return list(vars(self).keys())
71 raw = dict((var, getattr(self, var))
for var
in self.get_refl_vars())
75 return yaml.dump(self.to_yaml()).rstrip()
def xml_string(rootXml, addHeader=True)