Commit 0962e65f authored by Alexander Schrode's avatar Alexander Schrode Committed by oroulet

allow non unicode bytestring nodeid

parent b380a566
...@@ -520,7 +520,10 @@ class NodeId: ...@@ -520,7 +520,10 @@ class NodeId:
identifier = uuid.UUID(f"urn:uuid:{v}") identifier = uuid.UUID(f"urn:uuid:{v}")
elif k == "b": elif k == "b":
ntype = NodeIdType.ByteString ntype = NodeIdType.ByteString
identifier = bytes(v, 'utf-8') if v[0:2] == '0x':
identifier = bytes.fromhex(v[2:])
else:
identifier = v.encode()
elif k == "srv": elif k == "srv":
srv = int(v) srv = int(v)
elif k == "nsu": elif k == "nsu":
...@@ -549,7 +552,7 @@ class NodeId: ...@@ -549,7 +552,7 @@ class NodeId:
ntype = "g" ntype = "g"
elif self.NodeIdType == NodeIdType.ByteString: elif self.NodeIdType == NodeIdType.ByteString:
ntype = "b" ntype = "b"
identifier = identifier.decode() identifier = '0x' + identifier.hex()
string.append(f"{ntype}={identifier}") string.append(f"{ntype}={identifier}")
return ";".join(string) return ";".join(string)
......
...@@ -149,8 +149,10 @@ async def test_delete_nodes(opc): ...@@ -149,8 +149,10 @@ async def test_delete_nodes(opc):
async def test_node_bytestring(opc): async def test_node_bytestring(opc):
obj = opc.opc.nodes.objects obj = opc.opc.nodes.objects
var = await obj.add_variable(ua.ByteStringNodeId(b"VarByteString", 2), ua.QualifiedName("toto", 2), ua.UInt16(9)) var = await obj.add_variable(ua.ByteStringNodeId(b'VarByteString', 2), ua.QualifiedName("toto", 2), ua.UInt16(9))
node = opc.opc.get_node("ns=2;b=VarByteString") node = opc.opc.get_node(f"ns=2;b=VarByteString")
assert node == var
node = opc.opc.get_node(f"ns=2;b=0x{b'VarByteString'.hex()}")
assert node == var assert node == var
......
...@@ -390,6 +390,14 @@ def test_nodeid_bytestring(): ...@@ -390,6 +390,14 @@ def test_nodeid_bytestring():
s2 = n2.to_string() s2 = n2.to_string()
assert n == n2 assert n == n2
assert s == s2 assert s == s2
n = ua.ByteStringNodeId(Identifier=b'\x01\x00\x05\x55')
s = n.to_string()
n2 = ua.NodeId.from_string(s)
s2 = n2.to_string()
assert n == n2
assert s == s2
n = ua.NodeId.from_string('b=0xaabbccdd')
assert n.Identifier == b'\xaa\xbb\xcc\xdd'
def test__nodeid(): def test__nodeid():
......
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