Commit 91ab3c47 authored by Maxime Puys's avatar Maxime Puys Committed by ORD

Importing bytesting objects from XML in Python3 (#387)

* Fixup: replace on encoded string.

Replace methode was called on an encoded string (e.g.: when parsing
bytestring objects).
Inverted call to replace and string encoding.

* Fixup: bytestring tested against not encoded strings.
parent dbd12492
......@@ -230,12 +230,12 @@ class XMLParser(object):
if obj.value.tzinfo is None or obj.value.tzinfo.utcoffset(obj.value) is None:
utc.localize(obj.value) # FIXME Forcing to UTC if unaware, maybe should raise?
elif ntag in ("ByteString", "String"):
mytext = ua_type_to_python(val_el.text, ntag)
mytext = val_el.text
if mytext is None:
# Support importing null strings.
mytext = ""
mytext = mytext.replace('\n', '').replace('\r', '')
obj.value = mytext
obj.value = ua_type_to_python(mytext, ntag)
elif ntag == "Guid":
self._parse_contained_value(val_el, obj)
# Override parsed string type to guid.
......
......@@ -243,6 +243,14 @@ class XmlTests(object):
# o = self.opc.nodes.objects.add_variable(2, "xmlltext_array", [ua.QualifiedName("erert", 5), ua.QualifiedName("erert33", 6)])
# self._test_xml_var_type(o, "qualified_name_array")
def test_xml_bytestring(self):
o = self.opc.nodes.objects.add_variable(2, "xmlltext", "mytext".encode("utf8"), ua.VariantType.ByteString)
self._test_xml_var_type(o, "bytestring")
def test_xml_bytestring_array(self):
o = self.opc.nodes.objects.add_variable(2, "xmlltext_array", ["mytext".encode("utf8"), "errsadf".encode("utf8")], ua.VariantType.ByteString)
self._test_xml_var_type(o, "bytestring_array")
def test_xml_localizedtext(self):
o = self.opc.nodes.objects.add_variable(2, "xmlltext", ua.LocalizedText("mytext"))
self._test_xml_var_type(o, "localized_text")
......
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