Skip to content

Commit

Permalink
[dfg] Fix XML input reader
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Mar 3, 2019
1 parent abba169 commit 7e4d967
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tools/generator/dfg/input/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging

from lxml import etree
from pathlib import Path

LOGGER = logging.getLogger('dfg.input.xml')

Expand All @@ -22,15 +23,10 @@ def __init__(self, path):
self.tree = self._openDeviceXML(self.filename)

def _openDeviceXML(self, filename):
LOGGER.debug("Opening XML file '%s'", os.path.basename(self.filename))
with open(filename, 'r') as raw_file:
xml_file = raw_file.read()
xml_file = re.sub(' xmlns="[^"]+"', '', xml_file, count=1).encode('utf-8')
xmltree = None
try:
xmltree = etree.fromstring(xml_file, parser=XMLReader._PARSER)
except:
LOGGER.error("Failure to open XML file!")
LOGGER.debug("Opening XML file '%s'", os.path.basename(filename))
xml_file = Path(filename).read_text("utf-8", errors="replace")
xml_file = re.sub(' xmlns="[^"]+"', '', xml_file, count=1).encode("utf-8")
xmltree = etree.fromstring(xml_file, parser=XMLReader._PARSER)
return xmltree

def queryTree(self, query):
Expand Down Expand Up @@ -66,4 +62,4 @@ def __repr__(self):
return self.__str__()

def __str__(self):
return "XMLReader({}, [\n{}])".format(os.path.basename(self.filename), ",\n".join(map(str, self.properties)))
return "XMLReader({})".format(os.path.basename(self.filename))

0 comments on commit 7e4d967

Please sign in to comment.