From be6b2970aead6711a5cb9b9117fc459b88a100e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Tue, 3 Jul 2012 04:14:39 +0200 Subject: [PATCH] New function to pretty-print a ModuleState tree --- module_state.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/module_state.py b/module_state.py index 3444de9..222f23a 100644 --- a/module_state.py +++ b/module_state.py @@ -21,6 +21,19 @@ class ModuleState: """Get the name of the current node""" return self.name + def display(self, level = 0): + ret = "" + out = list() + for k in self.attributes: + out.append("%s : %s" % (k, self.attributes[k])) + ret += "%s%s { %s } = '%s'\n" % (' ' * level, self.name, ' ; '.join(out), self.content) + for c in self.childs: + ret += c.display(level + 2) + return ret + + def __str__(self): + return self.display() + def __getitem__(self, i): """Return the attribute asked""" return self.getAttribute(i)