From 17fad2a8ef3f22149fa58696d469a7a8b497fd0f Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 24 Sep 2007 00:43:07 +0000 Subject: [PATCH] * Fix wrong data type when just one station * Cleanup --- d-fuzz.py | 14 +++++++++++--- xmltodict.py | 7 ------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/d-fuzz.py b/d-fuzz.py index 0e426e2..47b55ec 100755 --- a/d-fuzz.py +++ b/d-fuzz.py @@ -71,15 +71,23 @@ class DFuzz: print "D-fuzz v"+self.version self.conf = self.get_conf_dict() print self.conf - - nb_stations = len(self.conf['d-fuzz']['station']) + + # Fix wrong type data from xmltodict when one station (*) + if isinstance(self.conf['d-fuzz']['station'], dict): + nb_stations = 1 + else: + nb_stations = len(self.conf['d-fuzz']['station']) print 'Number of stations : ' + str(nb_stations) # Create a Queue: #stream_pool = Queue.Queue ( 0 ) for i in range(0,nb_stations): - station = self.conf['d-fuzz']['station'][i] + # (*) idem + if isinstance(self.conf['d-fuzz']['station'], dict): + station = self.conf['d-fuzz']['station'] + else: + station = self.conf['d-fuzz']['station'][i] print station name = station['infos']['name'] channels = int(station['infos']['channels']) diff --git a/xmltodict.py b/xmltodict.py index e9a2f3f..b85d556 100644 --- a/xmltodict.py +++ b/xmltodict.py @@ -6,31 +6,25 @@ import xml.dom.minidom def haschilds(dom): - # Checks whether an element has any childs # containing real tags opposed to just text. - for childnode in dom.childNodes: if childnode.nodeName != "#text" and \ childnode.nodeName != "#cdata-section": return True - return False def indexchilds(dom, enc): childsdict = dict() - for childnode in dom.childNodes: name = childnode.nodeName.encode(enc) if name == "#text" or name == "#cdata-section": # ignore whitespaces continue - if haschilds(childnode): v = indexchilds(childnode, enc) else: v = childnode.childNodes[0].nodeValue.encode(enc) - if name in childsdict: if isinstance(childsdict[name], dict): # there is multiple instances of this node - convert to list @@ -38,7 +32,6 @@ def indexchilds(dom, enc): childsdict[name].append(v) else: childsdict[name] = v - return childsdict def xmltodict(data, enc=None): -- 2.39.5