def test_nodeid(): nid = ua.NodeId() assert nid.NodeIdType == ua.NodeIdType.TwoByte nid = ua.NodeId(446, 3, ua.NodeIdType.FourByte) assert nid.NodeIdType == ua.NodeIdType.FourByte d = nodeid_to_binary(nid) new_nid = nodeid_from_binary(io.BytesIO(d)) assert new_nid == nid assert new_nid.NodeIdType == ua.NodeIdType.FourByte assert new_nid.Identifier == 446 assert new_nid.NamespaceIndex == 3 tb = ua.TwoByteNodeId(53) fb = ua.FourByteNodeId(53) n = ua.NumericNodeId(53) n1 = ua.NumericNodeId(53, 0) s1 = ua.StringNodeId("53", 0) bs = ua.ByteStringNodeId(b"53", 0) gid = uuid.uuid4() g = ua.ByteStringNodeId(str(gid), 0) guid = ua.GuidNodeId(gid) assert tb == fb assert tb == n assert tb == n1 assert n1 == fb assert g != guid assert tb == nodeid_from_binary(ua.utils.Buffer(nodeid_to_binary(tb))) assert fb == nodeid_from_binary(ua.utils.Buffer(nodeid_to_binary(fb))) assert n == nodeid_from_binary(ua.utils.Buffer(nodeid_to_binary(n))) assert s1 == nodeid_from_binary(ua.utils.Buffer(nodeid_to_binary(s1))) assert bs == nodeid_from_binary(ua.utils.Buffer(nodeid_to_binary(bs))) assert guid == nodeid_from_binary(ua.utils.Buffer(nodeid_to_binary(guid)))
def test_null(): n = ua.NodeId(b'000000', 0, nodeidtype=ua.NodeIdType.Guid) assert n.is_null() assert n.has_null_identifier() n = ua.NodeId(b'000000', 1, nodeidtype=ua.NodeIdType.Guid) assert n.is_null() is False assert n.has_null_identifier() n = ua.NodeId() assert n.is_null() assert n.has_null_identifier() n = ua.NodeId(0, 0) assert n.is_null() assert n.has_null_identifier() n = ua.NodeId("", 0) assert n.is_null() assert n.has_null_identifier() n = ua.TwoByteNodeId(0) assert n.is_null() assert n.has_null_identifier() n = ua.NodeId(0, 3) assert n.is_null() is False assert n.has_null_identifier()
def _to_nodeid(nodeid): if isinstance(nodeid, int): return ua.TwoByteNodeId(nodeid) if isinstance(nodeid, Node): return nodeid.nodeid if isinstance(nodeid, ua.NodeId): return nodeid if type(nodeid) in (str, bytes): return ua.NodeId.from_string(nodeid) raise ua.UaError(f"Could not resolve '{nodeid}' to a type id")
def _to_nodeid(nodeid): if isinstance(nodeid, int): return ua.TwoByteNodeId(nodeid) elif isinstance(nodeid, Node): return nodeid.nodeid elif isinstance(nodeid, ua.NodeId): return nodeid elif type(nodeid) in (str, bytes): return ua.NodeId.from_string(nodeid) else: raise ua.UaError("Could not resolve '{0}' to a type id".format(nodeid))
def _make_relative_path(self, path): rpath = ua.RelativePath() for item in path: el = ua.RelativePathElement() el.ReferenceTypeId = ua.TwoByteNodeId(ua.ObjectIds.HierarchicalReferences) el.IsInverse = False el.IncludeSubtypes = True if isinstance(item, ua.QualifiedName): el.TargetName = item else: el.TargetName = ua.QualifiedName.from_string(item) rpath.Elements.append(el) return rpath
def test_nodeid_ordering(): a = ua.NodeId(2000, 1) b = ua.NodeId(3000, 1) c = ua.NodeId(20, 0) d = ua.NodeId("tititu", 1) e = ua.NodeId("aaaaa", 1) f = ua.NodeId("aaaaa", 2) g = ua.NodeId(uuid.uuid4(), 1) h = ua.TwoByteNodeId(2001) i = ua.NodeId(b"lkjkl", 1, ua.NodeIdType.ByteString) j = ua.NodeId(b"aaa", 5, ua.NodeIdType.ByteString) mylist = [a, b, c, d, e, f, g, h, i, j] mylist.sort() expected = [h, c, a, b, e, d, f, g, i, j] assert mylist == expected
def test_nodeid_ordering(): a = ua.NodeId(2000, 1) b = ua.NodeId(3000, 1) c = ua.NodeId(20, 0) d = ua.NodeId("tititu", 1) e = ua.NodeId("aaaaa", 1) f = ua.NodeId("aaaaa", 2) g = ua.NodeId(uuid.uuid4(), 1) h = ua.TwoByteNodeId(201) i = ua.NodeId(b"lkjkl", 1, ua.NodeIdType.ByteString) j = ua.NodeId(b"aaa", 5, ua.NodeIdType.ByteString) mylist = [a, b, c, d, e, f, g, h, i, j] mylist.sort() expected = [h, c, a, b, e, d, f, g, i, j] expected = [c, h, a, b, e, d, f, g, i, j] # FIXME: make sure this does not break some client/server assert mylist == expected
def test_null(): n = ua.NodeId() assert n.is_null() assert n.has_null_identifier() n = ua.NodeId(0, 0) assert n.is_null() assert n.has_null_identifier() n = ua.NodeId("", 0) assert n.is_null() assert n.has_null_identifier() n = ua.TwoByteNodeId(0) assert n.is_null() assert n.has_null_identifier() n = ua.NodeId(0, 3) assert n.is_null() is False assert n.has_null_identifier()
def get_server_node(self): """ Get Server node of server. Returns a Node object. """ return self.get_node(ua.TwoByteNodeId(ua.ObjectIds.Server))
def get_objects_node(self): """ Get Objects node of server. Returns a Node object. """ return self.get_node(ua.TwoByteNodeId(ua.ObjectIds.ObjectsFolder))
def get_root_node(self): """ Get Root node of server. Returns a Node object. """ return self.get_node(ua.TwoByteNodeId(ua.ObjectIds.RootFolder))
def get_objects_node(self): _logger.info("get_objects_node") return self.get_node(ua.TwoByteNodeId(ua.ObjectIds.ObjectsFolder))
def get_root_node(self): return self.get_node(ua.TwoByteNodeId(ua.ObjectIds.RootFolder))