dasbus.server.container module

class DBusContainer(message_bus, namespace, basename=None)[source]

Bases: object

The container of DBus objects.

A DBus container should be used to dynamically publish Publishable objects within the same namespace. It generates a unique DBus path for each object. It is able to resolve a DBus path into an object and an object into a DBus path.

Example:

# Create a container of tasks.
container = DBusContainer(
    namespace=("my", "project"),
    basename="Task",
    message_bus=DBus
)

# Publish a task.
path = container.to_object_path(MyTask())

# Resolve an object path into a task.
task = container.from_object_path(path)
from_object_path(object_path: ObjPath)[source]

Convert a DBus path to a published object.

If no published object is found for the given DBus path, raise DBusContainerError.

Parameters

object_path – a DBus path

Returns

a published object

from_object_path_list(object_paths: List[ObjPath])[source]

Convert DBus paths to published objects.

Parameters

object_paths – a list of DBus paths

Returns

a list of published objects

set_namespace(namespace)[source]

Set the namespace.

All DBus objects from the container should use the same namespace, so the namespace should be set up before any of the DBus objects are published.

Parameters

namespace – a sequence of names

to_object_path(obj) ObjPath[source]

Convert a publishable object to a DBus path.

If no DBus path is found for the given object, publish the object on the container message bus with a unique DBus path generated from the container namespace.

Parameters

obj – a publishable object

Returns

a DBus path

to_object_path_list(objects) List[ObjPath][source]

Convert publishable objects to DBus paths.

Parameters

objects – a list of publishable objects

Returns

a list of DBus paths

exception DBusContainerError[source]

Bases: Exception

General exception for DBus container errors.