Commit 0261d3ed authored by Fabian Beitler's avatar Fabian Beitler Committed by GitHub

Replace lxml with xml.etree.ElementTree (#346)

* Replace lxml with xml.etree.ElementTree
Replace iter() with iterfind()
Remove lxml from setup.py
Remove done FIXME Graffitti
Remove lxml from travis

* Replace wildcard iter via iter over every element to be python3.7 compatible
parent 9e5bc78a
......@@ -22,7 +22,6 @@ jobs:
install:
- pip install python-dateutil
- pip install pytz
- pip install lxml
- pip install aiofiles
- pip install aiosqlite
- pip install pytest --upgrade
......
......@@ -9,8 +9,7 @@ import logging
# The next two imports are for generated code
from datetime import datetime
from enum import Enum, IntEnum, EnumMeta
from lxml import objectify
from xml.etree import ElementTree as ET
from asyncua import ua
from .structures104 import get_default_value, clean_name
......@@ -119,19 +118,21 @@ class StructGenerator(object):
self.model = []
def make_model_from_string(self, xml):
obj = objectify.fromstring(xml)
obj = ET.fromstring(xml)
self._make_model(obj)
def make_model_from_file(self, path):
obj = objectify.parse(path)
obj = ET.parse(path)
root = obj.getroot()
self._make_model(root)
def _make_model(self, root):
enums = {}
for child in root.iter("{*}EnumeratedType"):
for child in root:
if child.tag.endswith("EnumeratedType"):
intenum = EnumType(child.get("Name"))
for xmlfield in child.iter("{*}EnumeratedValue"):
for xmlfield in child:
if xmlfield.tag.endswith("EnumeratedValue"):
name = xmlfield.get("Name")
value = xmlfield.get("Value")
enumvalue = EnumeratedValue(name, value)
......@@ -139,10 +140,13 @@ class StructGenerator(object):
enums[child.get("Name")] = value
self.model.append(intenum)
for child in root.iter("{*}StructuredType"):
for child in root:
if child.tag.endswith("StructuredType"):
struct = Struct(child.get("Name"))
array = False
for xmlfield in child.iter("{*}Field"):
# these lines can be reduced in >= Python3.8 with root.iterfind("{*}Field") and similar
for xmlfield in child:
if xmlfield.tag.endswith("Field"):
name = xmlfield.get("Name")
if name.startswith("NoOf"):
array = True
......
......@@ -110,7 +110,6 @@ class XMLParser:
self.logger = logging.getLogger(__name__)
self._retag = re.compile(r"(\{.*\})(.*)")
self.root = None
# FIXME: hard to get these xml namespaces with ElementTree, we may have to shift to lxml
self.ns = {
'base': "http://opcfoundation.org/UA/2011/03/UANodeSet.xsd",
'uax': "http://opcfoundation.org/UA/2008/02/Types.xsd",
......
......@@ -15,7 +15,7 @@ setup(
packages=find_packages(),
provides=["asyncua"],
license="GNU Lesser General Public License v3 or later",
install_requires=["aiofiles", "aiosqlite", "python-dateutil", "pytz", "lxml", 'cryptography'],
install_requires=["aiofiles", "aiosqlite", "python-dateutil", "pytz", 'cryptography'],
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment