class documentation

class BaseServer(Generic[_UaObjectType]):

Constructor: BaseServer(**kwargs)

View In Hierarchy

Base class for both client RemoteServer and server Server.

Method __init__ Cooperative constructor.
Method find Return all objects whose canonical path matches the glob pattern (see ObjectPath.match), in tree order.
Method get_ua_object Return the UaObject which corresponds to the given ua_node.
Method get_ua_object_optional Return the UaObject which corresponds to the given ua_node or None.
Method register_ua_object Register the given UaObject to the server, by node and by its canonical path and aliases.
Method resolve Return the object at path, its canonical path or one of its aliases.
Method resolve_optional Return the object at path, its canonical path or one of its aliases, or None.
Method ua_from_qualified_name Convert from our QualifiedName to ua.QualifiedName.
Method ua_get_namespace_index Return the namespace index for the given namespace uri.
Method ua_get_namespace_uri Return the namespace URI for the given namespace index.
Method ua_get_node_id Return the complete OPC UA node ID for the given definition.
Method ua_to_node_id_definition Convert the given node ID to a node ID definition.
Method ua_to_qualified_name Convert ua.QualifiedName to our QualifiedName.
Method unregister_ua_object Unregister the given UaObject from the server, by node and by its canonical path and aliases.
Method _clear_ua_objects Forget all registered objects, by node and by path (e.g. before a client browses again).
Method _register_path Map path to ua_object; a path already taken by another object keeps that object.
Instance Variable _namespace_map Undocumented
Instance Variable _ua_objects Maps OPC UA nodes to UaObjects with weak references.
Instance Variable _ua_objects_by_path Maps canonical paths and aliases to UaObjects with weak references.
def __init__(self, **kwargs):

Cooperative constructor.

def find(self, pattern: str) -> list[_UaObjectType]:

Return all objects whose canonical path matches the glob pattern (see ObjectPath.match), in tree order.

Raises
ValueErrorIf pattern is no valid pattern.
def get_ua_object(self, ua_node_id: ua.NodeId) -> _UaObjectType:

Return the UaObject which corresponds to the given ua_node.

Raises
KeyErrorIf no UaObject is found.
def get_ua_object_optional(self, ua_node_id: ua.NodeId) -> _UaObjectType | None:

Return the UaObject which corresponds to the given ua_node or None.

def register_ua_object(self, ua_object: _UaObjectType):

Register the given UaObject to the server, by node and by its canonical path and aliases.

Objects register top-down: the path is taken now, so the parent must already be registered and can't change anymore (BaseUaObject._set_parent).

Raises
RuntimeErrorIf the object has a parent that isn't registered.
def resolve(self, path: ObjectPath | str) -> _UaObjectType:

Return the object at path, its canonical path or one of its aliases.

Raises
KeyErrorIf no object has this path.
ValueErrorIf path is a str that is no valid path.
def resolve_optional(self, path: ObjectPath | str) -> _UaObjectType | None:

Return the object at path, its canonical path or one of its aliases, or None.

Raises
ValueErrorIf path is a str that is no valid path.
def ua_from_qualified_name(self, qualified_name: QualifiedName) -> ua.QualifiedName:

Convert from our QualifiedName to ua.QualifiedName.

def ua_get_namespace_index(self, uri: str | type[NamespaceProvider]) -> ua.Int16:

Return the namespace index for the given namespace uri.

Raises
KeyErrorIf the namespace URI is unknown.
def ua_get_namespace_uri(self, index: int) -> str:

Return the namespace URI for the given namespace index.

Raises
KeyErrorIf the server has no namespace at index.
def ua_get_node_id(self, definition: NodeIdDefinition) -> ua.NodeId:

Return the complete OPC UA node ID for the given definition.

Raises
KeyErrorIf the namespace URI of the definition is unknown.
def ua_to_node_id_definition(self, node_id: ua.NodeId) -> NodeIdDefinition:

Convert the given node ID to a node ID definition.

An ua.ExpandedNodeId uses its NamespaceUri if set.

Raises
KeyErrorIf the namespace index is unknown.
ValueErrorIf an ua.ExpandedNodeId points to another server.
def ua_to_qualified_name(self, qualified_name: ua.QualifiedName) -> QualifiedName:
def unregister_ua_object(self, ua_object: _UaObjectType):

Unregister the given UaObject from the server, by node and by its canonical path and aliases.

def _clear_ua_objects(self):

Forget all registered objects, by node and by path (e.g. before a client browses again).

def _register_path(self, path: ObjectPath, ua_object: _UaObjectType):

Map path to ua_object; a path already taken by another object keeps that object.

_namespace_map: dict[str, int] =

Undocumented

_ua_objects: WeakValueDictionary[ua.NodeId, _UaObjectType] =

Maps OPC UA nodes to UaObjects with weak references.

_ua_objects_by_path: WeakValueDictionary[ObjectPath, _UaObjectType] =

Maps canonical paths and aliases to UaObjects with weak references.