]> git.parisson.com Git - deefuzzer.git/commitdiff
use pure xml.etree method to parse XML (fixes #32)
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 7 Sep 2021 22:18:33 +0000 (00:18 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 7 Sep 2021 22:18:33 +0000 (00:18 +0200)
deefuzzer/core.py
deefuzzer/tools/__init__.py
deefuzzer/tools/utils.py
deefuzzer/tools/xmltodict3.py [new file with mode: 0644]

index 2b87a88c313ca3ad9b444b692751195b100eaeb4..1126ba925a227003b32f5e2e9cd92846e57e6fcb 100644 (file)
@@ -271,7 +271,7 @@ class DeeFuzzer(Thread):
                     try:
                         if 'station_instance' in self.station_settings[i]:
                             # Check for station running here
-                            if self.station_settings[i]['station_instance'].isAlive():
+                            if self.station_settings[i]['station_instance'].is_alive:
                                 # Station exists and is alive.  Don't recreate.
                                 self.station_settings[i]['retries'] = 0
                                 continue
index 0ccf1273257b945413e3418bd0aec7956464af62..f68aba8f098330e222186d44bb6d43908a7f6858 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from .xmltodict import *
+from .xmltodict3 import *
 from .PyRSS2Gen import *
 from .mediabase import *
 from .mp3 import *
index 7b74f07f4475c368829da692cd92f0df8a80e9a7..7b708570e8b0b4841354ff0ce292fd8f9859ce72 100644 (file)
@@ -15,8 +15,9 @@ import re
 import string
 import mimetypes
 from itertools import chain
+from xml.etree import cElementTree as ElementTree
 from deefuzzer.tools import *
-import xmltodict
+
 
 mimetypes.add_type('application/x-yaml', '.yaml')
 
@@ -88,10 +89,10 @@ def get_conf_dict(file):
 
     # Do the type check first, so we don't load huge files that won't be used
     if 'xml' in mime_type:
-        confile = open(file, 'r')
-        data = confile.read()
-        confile.close()
-        return xmltodict.parse(data)
+        tree = ElementTree.parse(file)
+        root = tree.getroot()
+        xmldict = etree_to_dict(root)
+        return xmldict
 
     elif 'yaml' in mime_type or 'yml' in mime_type:
         import yaml
diff --git a/deefuzzer/tools/xmltodict3.py b/deefuzzer/tools/xmltodict3.py
new file mode 100644 (file)
index 0000000..9715061
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# taken from https://stackoverflow.com/questions/2148119/how-to-convert-an-xml-string-to-a-dictionary
+# thanks to K3---rnc
+
+
+from collections import defaultdict
+
+def etree_to_dict(t):
+    d = {t.tag: {} if t.attrib else None}
+    children = list(t)
+    if children:
+        dd = defaultdict(list)
+        for dc in map(etree_to_dict, children):
+            for k, v in dc.items():
+                dd[k].append(v)
+        d = {t.tag: {k:v[0] if len(v) == 1 else v for k, v in dd.items()}}
+    if t.attrib:
+        d[t.tag].update(('@' + k, v) for k, v in t.attrib.items())
+    if t.text:
+        text = t.text.strip()
+        if children or t.attrib:
+            if text:
+              d[t.tag]['#text'] = text
+        else:
+            d[t.tag] = text
+    return d
\ No newline at end of file