]> git.parisson.com Git - deefuzzer.git/commitdiff
* Fix wrong data type when just one station
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 24 Sep 2007 00:43:07 +0000 (00:43 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 24 Sep 2007 00:43:07 +0000 (00:43 +0000)
* Cleanup

d-fuzz.py
xmltodict.py

index 0e426e20ea214680cfa5a4b207ebbbc067bf09ef..47b55ecf04eb1fcef5dc8f7ba472a8f04ac185b8 100755 (executable)
--- 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'])
index e9a2f3f9afac51791a0c01fb14a8499fd9b3a390..b85d556d294bd1ab43b6bca763e66420673350bc 100644 (file)
@@ -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):