.\" Man page generated from reStructuredText. . .TH "DASBUS" "1" "Dec 15, 2022" "" "dasbus" .SH NAME dasbus \- dasbus . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .sp Dasbus is a DBus library written in Python 3, based on GLib and inspired by pydbus. The code used to be part of the \fI\%Anaconda Installer\fP project. It was based on the \fI\%pydbus\fP library, but we replaced it with our own solution because its upstream development stalled. The dasbus library is a result of this effort. .SH REQUIREMENTS .INDENT 0.0 .IP \(bu 2 Python 3.6+ .IP \(bu 2 PyGObject 3 .UNINDENT .sp You can install \fI\%PyGObject\fP provided by your operating system or use PyPI. The system package is usually called \fBpython3\-gi\fP, \fBpython3\-gobject\fP or \fBpygobject3\fP\&. See the \fI\%instructions\fP for your platform (only for PyGObject, you don\(aqt need cairo or GTK). .sp The library is known to work with Python 3.8, PyGObject 3.34 and GLib 2.63, but these are not the required minimal versions. .SH INSTALLATION .sp Install the package from \fI\%PyPI\fP or install the package provided by your operating system if available. .SS Install from PyPI .sp Follow the instructions above to install the requirements before you install \fBdasbus\fP with \fBpip\fP\&. The required dependencies has to be installed manually in this case. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C pip3 install dasbus .ft P .fi .UNINDENT .UNINDENT .SS Install on Arch Linux .sp Build and install the community package from the \fI\%Arch User Repository\fP\&. Follow the \fI\%guidelines\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C git clone https://aur.archlinux.org/python\-dasbus.git cd python\-dasbus makepkg \-si .ft P .fi .UNINDENT .UNINDENT .SS Install on Debian / Ubuntu .sp Install the system package on Debian 11+ or Ubuntu 22.04+. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C sudo apt install python3\-dasbus .ft P .fi .UNINDENT .UNINDENT .SS Install on Fedora / CentOS / RHEL .sp Install the system package on Fedora 31+, CentOS Stream 8+ or RHEL 8+. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C sudo dnf install python3\-dasbus .ft P .fi .UNINDENT .UNINDENT .SS Install on openSUSE .sp Install the system package on openSUSE Tumbleweed or openSUSE Leap 15.2+. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C sudo zypper install python3\-dasbus .ft P .fi .UNINDENT .UNINDENT .SS Development and testing .sp Install \fI\%podman\fP and use the following command to run all tests in a container. It doesn\(aqt require any additional dependencies: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C make container\-ci .ft P .fi .UNINDENT .UNINDENT .sp Use the command below to run only the unit tests: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C make container\-ci CI_CMD="make test" .ft P .fi .UNINDENT .UNINDENT .SS dasbus vs pydbus .sp The dasbus library used to be based on \fI\%pydbus\fP, but it was later reimplemented. We have changed the API and the implementation of the library based on our experience with pydbus. However, it should be possible to modify dasbus classes to work the same way as pydbus classes. .SS What is new .INDENT 0.0 .IP \(bu 2 Support for asynchronous DBus calls: DBus methods can be called asynchronously. .IP \(bu 2 Support for Unix file descriptors: It is possible to send or receive Unix file descriptors. .IP \(bu 2 Mapping DBus errors to exceptions: Use Python exceptions to propagate and handle DBus errors. Define your own rules for mapping errors to exceptions and back. See the \fBErrorMapper\fP class .IP \(bu 2 Support for type hints: Use Python type hints from \fBdasbus.typing\fP to define DBus types. .IP \(bu 2 Generating XML specifications: Automatically generate XML specifications from Python classes with the \fBdbus_interface\fP decorator. .IP \(bu 2 Support for DBus structures: Represent DBus structures (dictionaries of variants) by Python objects. See the \fBDBusData\fP class. .IP \(bu 2 Support for groups of DBus objects: Use DBus containers from \fBdasbus.server.container\fP to publish groups of Python objects. .IP \(bu 2 Composition over inheritance: The library follows the principle of composition over inheritance. It allows to easily change the default behaviour. .IP \(bu 2 Lazy DBus connections: DBus connections are established on demand. .IP \(bu 2 Lazy DBus proxies: Attributes of DBus proxies are created on demand. .UNINDENT .SS What is different .INDENT 0.0 .IP \(bu 2 No context managers: There are no context managers in dasbus. Context managers and event loops don\(aqt work very well together. .IP \(bu 2 No auto\-completion: There is no support for automatic completion of DBus names and paths. We recommend to work with constants defined by classes from \fBdasbus.identifier\fP instead of strings. .IP \(bu 2 No unpacking of variants: The dasbus library doesn\(aqt unpack variants by default. It means that values received from DBus match the types declared in the XML specification. Use the \fBget_native\fP function to unpack the values. .IP \(bu 2 Obtaining proxy objects: Call the \fBget_proxy\fP method to get a proxy of the specified DBus object. .IP \(bu 2 No single\-interface view: DBus proxies don\(aqt support single\-interface views. Use the \fBInterfaceProxy\fP class to access a specific interface of a DBus object. .IP \(bu 2 Higher priority of standard interfaces: If there is a DBus interface in the XML specification that redefines a member of a standard interface, the DBus proxy will choose a member of the standard interface. Use the \fBInterfaceProxy\fP class to access a specific interface of a DBus object. .IP \(bu 2 No support for help: Members of DBus proxies are created lazily, so the build\-in \fBhelp\fP function doesn\(aqt return useful information about the DBus interfaces. .IP \(bu 2 Watching DBus names: Use \fBa service observer\fP to watch a DBus name. .IP \(bu 2 Acquiring DBus names: Call the \fBregister_service\fP method to acquire a DBus name. .IP \(bu 2 Providing XML specifications: Use the \fB__dbus_xml__\fP attribute to provide the XML specification of a DBus object. Or you can generate it from the code using the \fBdbus_interface\fP decorator. .IP \(bu 2 No support for polkit: There is no support for the DBus service \fBorg.freedesktop.PolicyKit1\fP\&. .UNINDENT .SS What is the same (for now) .INDENT 0.0 .IP \(bu 2 No support for other event loops: Dasbus uses GLib as its backend, so it requires to use the GLib event loop. However, the GLib part of dasbus is separated from the rest of the code, so it shouldn\(aqt be too difficult to add support for a different backend. It would be necessary to replace \fBdasbus.typing.Variant\fP and \fBdasbus.typing.VariantType\fP with their abstractions and reorganize the code. .IP \(bu 2 No support for org.freedesktop.DBus.ObjectManager: There is no support for object managers, however the \fBDBus containers\fP could be a good starting point. .UNINDENT .SS Public API .SS dasbus.client package .SS dasbus.client.handler module .INDENT 0.0 .TP .B class AbstractClientObjectHandler(message_bus, service_name, object_path) Bases: \fBobject\fP .sp The abstract handler of a remote DBus object. .INDENT 7.0 .TP .B create_member(interface_name, member_name) Create a member of the DBus object. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBinterface_name\fP \-\- a name of the interface .IP \(bu 2 \fBmember_name\fP \-\- a name of the member .UNINDENT .TP .B Returns a signal, a method or a property .UNINDENT .UNINDENT .INDENT 7.0 .TP .B abstract disconnect_members() Disconnect members of the DBus object. .sp Unsubscribe from DBus signals and disconnect all registered callbacks of the proxy signals. .UNINDENT .INDENT 7.0 .TP .B property object_path DBus object path. .INDENT 7.0 .TP .B Returns a DBus path .UNINDENT .UNINDENT .INDENT 7.0 .TP .B property service_name DBus service name. .INDENT 7.0 .TP .B Returns a DBus name .UNINDENT .UNINDENT .INDENT 7.0 .TP .B property specification DBus specification. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class ClientObjectHandler(message_bus, service_name, object_path, error_mapper=None, client=, signal_factory=) Bases: \fI\%dasbus.client.handler.AbstractClientObjectHandler\fP .sp The client handler of a DBus object. .INDENT 7.0 .TP .B disconnect_members() Disconnect members of the DBus object. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class GLibClient Bases: \fBobject\fP .sp The low\-level DBus client library based on GLib. .INDENT 7.0 .TP .B DBUS_TIMEOUT_NONE = 2147483647 .UNINDENT .INDENT 7.0 .TP .B classmethod async_call(connection, service_name, object_path, interface_name, method_name, parameters, reply_type, callback, callback_args=(), flags=0, timeout=2147483647) Asynchronously call a DBus method. .UNINDENT .INDENT 7.0 .TP .B classmethod get_remote_error_message(error) Get a message of the remote DBus error. .UNINDENT .INDENT 7.0 .TP .B classmethod get_remote_error_name(error) Get a DBus name of the remote DBus error. .UNINDENT .INDENT 7.0 .TP .B classmethod is_remote_error(error) Is it a remote DBus error? .UNINDENT .INDENT 7.0 .TP .B classmethod is_timeout_error(error) Is it a timeout error? .UNINDENT .INDENT 7.0 .TP .B classmethod subscribe_signal(connection, service_name, object_path, interface_name, signal_name, callback, callback_args=(), flags=0) Subscribe to a signal. .INDENT 7.0 .TP .B Returns a callback to unsubscribe .UNINDENT .UNINDENT .INDENT 7.0 .TP .B classmethod sync_call(connection, service_name, object_path, interface_name, method_name, parameters, reply_type, flags=0, timeout=2147483647) Synchronously call a DBus method. .INDENT 7.0 .TP .B Returns a result of the DBus call .UNINDENT .UNINDENT .UNINDENT .SS dasbus.client.observer module .INDENT 0.0 .TP .B class DBusObserver(message_bus, service_name, monitoring=) Bases: \fBobject\fP .sp Base class for DBus observers. .sp This class is recommended to use only to watch the availability of a service on DBus. It doesn\(aqt provide any support for accessing objects provided by the service. .sp Usage: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C # Create the observer and connect to its signals. observer = DBusObserver(SystemBus, "org.freedesktop.NetworkManager") def callback1(observer): print("Service is available!") def callback2(observer): print("Service is unavailable!") observer.service_available.connect(callback1) observer.service_unavailable.connect(callback2) # Connect to the service once it is available. observer.connect_once_available() # Disconnect the observer. observer.disconnect() .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B connect_once_available() Connect to the service once it is available. .sp The observer is not connected to the service until it emits the service_available signal. .UNINDENT .INDENT 7.0 .TP .B disconnect() Disconnect from the service. .sp Disconnect from the service if it is connected and stop watching its availability. .UNINDENT .INDENT 7.0 .TP .B property is_service_available The proxy can be accessed. .UNINDENT .INDENT 7.0 .TP .B property service_available Signal that emits when the service is available. .sp Signal emits this class as an argument. You have to call the watch method to activate the signals. .UNINDENT .INDENT 7.0 .TP .B property service_name Returns a DBus name. .UNINDENT .INDENT 7.0 .TP .B property service_unavailable Signal that emits when the service is unavailable. .sp Signal emits this class as an argument. You have to call the watch method to activate the signals. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B exception DBusObserverError Bases: \fBException\fP .sp Exception class for the DBus observers. .UNINDENT .INDENT 0.0 .TP .B class GLibMonitoring Bases: \fBobject\fP .sp The low\-level DBus monitoring library based on GLib. .INDENT 7.0 .TP .B classmethod watch_name(connection, name, flags=0, name_appeared=None, name_vanished=None) Watch a service name on the DBus connection. .UNINDENT .UNINDENT .SS dasbus.client.property module .INDENT 0.0 .TP .B class PropertyProxy(getter, setter) Bases: \fBobject\fP .sp Proxy of a remote DBus property. .sp It can be used to define instance attributes. .INDENT 7.0 .TP .B get() Get the value of the DBus property. .UNINDENT .INDENT 7.0 .TP .B set(value) Set the value of the DBus property. .UNINDENT .UNINDENT .SS dasbus.client.proxy module .INDENT 0.0 .TP .B class AbstractObjectProxy(message_bus, service_name, object_path, handler_factory=, **handler_arguments) Bases: \fBobject\fP .sp Abstract proxy of a remote DBus object. .UNINDENT .INDENT 0.0 .TP .B class InterfaceProxy(message_bus, service_name, object_path, interface_name, *args, **kwargs) Bases: \fI\%dasbus.client.proxy.AbstractObjectProxy\fP .sp Proxy of a remote DBus interface. .UNINDENT .INDENT 0.0 .TP .B class ObjectProxy(*args, **kwargs) Bases: \fI\%dasbus.client.proxy.AbstractObjectProxy\fP .sp Proxy of a remote DBus object. .UNINDENT .INDENT 0.0 .TP .B disconnect_proxy(proxy) Disconnect the DBus proxy from the remote object. .INDENT 7.0 .TP .B Parameters \fBproxy\fP \-\- a DBus proxy .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_object_path(proxy) Get an object path of the remote DBus object. .INDENT 7.0 .TP .B Parameters \fBproxy\fP \-\- a DBus proxy .TP .B Returns a DBus path .UNINDENT .UNINDENT .SS dasbus.server package .SS dasbus.server.container module .INDENT 0.0 .TP .B class DBusContainer(message_bus, namespace, basename=None) Bases: \fBobject\fP .sp The container of DBus objects. .sp 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. .sp Example: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C # 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) .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B from_object_path(object_path: ObjPath) Convert a DBus path to a published object. .sp If no published object is found for the given DBus path, raise DBusContainerError. .INDENT 7.0 .TP .B Parameters \fBobject_path\fP \-\- a DBus path .TP .B Returns a published object .UNINDENT .UNINDENT .INDENT 7.0 .TP .B from_object_path_list(object_paths: List[ObjPath]) Convert DBus paths to published objects. .INDENT 7.0 .TP .B Parameters \fBobject_paths\fP \-\- a list of DBus paths .TP .B Returns a list of published objects .UNINDENT .UNINDENT .INDENT 7.0 .TP .B set_namespace(namespace) Set the namespace. .sp 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. .INDENT 7.0 .TP .B Parameters \fBnamespace\fP \-\- a sequence of names .UNINDENT .UNINDENT .INDENT 7.0 .TP .B to_object_path(obj) -> ObjPath Convert a publishable object to a DBus path. .sp 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. .INDENT 7.0 .TP .B Parameters \fBobj\fP \-\- a publishable object .TP .B Returns a DBus path .UNINDENT .UNINDENT .INDENT 7.0 .TP .B to_object_path_list(objects) -> List[ObjPath] Convert publishable objects to DBus paths. .INDENT 7.0 .TP .B Parameters \fBobjects\fP \-\- a list of publishable objects .TP .B Returns a list of DBus paths .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B exception DBusContainerError Bases: \fBException\fP .sp General exception for DBus container errors. .UNINDENT .SS dasbus.server.handler module .INDENT 0.0 .TP .B class AbstractServerObjectHandler(message_bus, object_path, obj) Bases: \fBobject\fP .sp The abstract handler of a published object. .INDENT 7.0 .TP .B abstract connect_object() Connect the object to DBus. .sp Handle emitted signals of the object with the _emit_signal method and handle incoming DBus calls with the _handle_call method. .UNINDENT .INDENT 7.0 .TP .B abstract disconnect_object() Disconnect the object from DBus. .sp Unregister the object and disconnect all signals. .UNINDENT .INDENT 7.0 .TP .B property specification DBus specification. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class GLibServer Bases: \fBobject\fP .sp The low\-level DBus server library based on GLib. .INDENT 7.0 .TP .B classmethod emit_signal(connection, object_path, interface_name, signal_name, parameters, destination=None) Emit a DBus signal. .UNINDENT .INDENT 7.0 .TP .B classmethod get_call_info(invocation) Get information about the DBus call. .sp Supported items: .INDENT 7.0 .INDENT 3.5 sender str: The bus name that invoked the method .UNINDENT .UNINDENT .sp There can be more supported items in the future. .INDENT 7.0 .TP .B Parameters \fBinvocation\fP \-\- an invocation of a DBus call .TP .B Returns a dictionary of information about the DBus call .UNINDENT .UNINDENT .INDENT 7.0 .TP .B classmethod register_object(connection, object_path, object_xml, callback, callback_args=()) Register an object on DBus. .UNINDENT .INDENT 7.0 .TP .B classmethod set_call_error(invocation, error_name, error_message) Set the error of the DBus call. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBinvocation\fP \-\- an invocation of a DBus call .IP \(bu 2 \fBerror_name\fP \-\- a DBus name of the error .IP \(bu 2 \fBerror_message\fP \-\- an error message .UNINDENT .UNINDENT .UNINDENT .INDENT 7.0 .TP .B classmethod set_call_reply(invocation, out_type, out_value) Set the reply of the DBus call. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBinvocation\fP \-\- an invocation of a DBus call .IP \(bu 2 \fBout_type\fP \-\- a type of the reply .IP \(bu 2 \fBout_value\fP \-\- a value of the reply .UNINDENT .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class ServerObjectHandler(message_bus, object_path, obj, error_mapper=None, server=, signal_factory=) Bases: \fI\%dasbus.server.handler.AbstractServerObjectHandler\fP .sp The handler of an object published on DBus. .INDENT 7.0 .TP .B connect_object() Connect the object to DBus. .UNINDENT .INDENT 7.0 .TP .B disconnect_object() Disconnect the object from DBus. .UNINDENT .UNINDENT .SS dasbus.server.interface module .INDENT 0.0 .TP .B accepts_additional_arguments(method) Decorator for accepting extra arguments in a DBus method. .sp The decorator allows the server object handler to propagate additional information about the DBus call into the decorated method. .sp Use a dictionary of keyword arguments: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @accepts_additional_arguments def Method(x: Int, y: Str, **info): pass .ft P .fi .UNINDENT .UNINDENT .sp Or use keyword only parameters: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @accepts_additional_arguments def Method(x: Int, y: Str, *, call_info): pass .ft P .fi .UNINDENT .UNINDENT .sp At this moment, the library provides only the call_info argument generated by GLibServer.get_call_info, but the additional arguments can be customized in the _get_additional_arguments method of the server object handler. .INDENT 7.0 .TP .B Parameters \fBmethod\fP \-\- a DBus method .TP .B Returns a DBus method with a flag .UNINDENT .UNINDENT .INDENT 0.0 .TP .B are_additional_arguments_supported(method) Does the given DBus method accept additional arguments? .INDENT 7.0 .TP .B Parameters \fBmethod\fP \-\- a DBus method .TP .B Returns True or False .UNINDENT .UNINDENT .INDENT 0.0 .TP .B dbus_class(cls) DBus class. .sp A new DBus class can be defined as: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @dbus_class class Class(Interface): ... .ft P .fi .UNINDENT .UNINDENT .sp DBus class can implement DBus interfaces, but it cannot define a new interface. .sp The DBus XML specification will be generated from implemented interfaces (inherited) and it will be accessible as: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C Class.__dbus_xml__ .ft P .fi .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B dbus_interface(interface_name, namespace=()) DBus interface. .sp A new DBus interface can be defined as: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @dbus_interface class Interface(): ... .ft P .fi .UNINDENT .UNINDENT .sp The interface will be generated from the given class cls with a name interface_name and added to the DBus XML specification of the class. .sp The XML specification is accessible as: \&.. code\-block:: python .INDENT 7.0 .INDENT 3.5 Interface.__dbus_xml__ .UNINDENT .UNINDENT .sp It is conventional for member names on DBus to consist of capitalized words with no punctuation. The generator of the XML specification enforces this convention to prevent unintended changes in the specification. You can provide the XML specification yourself, or override the generator class to work around these constraints. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBinterface_name\fP \-\- a DBus name of the interface .IP \(bu 2 \fBnamespace\fP \-\- a sequence of strings .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class dbus_signal(definition=None, factory=) Bases: \fBobject\fP .sp DBus signal. .sp Can be used as: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C Signal = dbus_signal() .ft P .fi .UNINDENT .UNINDENT .sp Or as a method decorator: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @dbus_signal def Signal(x: Int, y: Double): pass .ft P .fi .UNINDENT .UNINDENT .sp Signal is defined by the type hints of a decorated method. This method is accessible as: signal.definition .sp If the signal is not defined by a method, it is expected to have no arguments and signal.definition is equal to None. .UNINDENT .INDENT 0.0 .TP .B get_xml(obj) Return XML specification of an object. .INDENT 7.0 .TP .B Parameters \fBobj\fP \-\- an object decorated with @dbus_interface or @dbus_class .TP .B Returns a string with XML specification .UNINDENT .UNINDENT .SS dasbus.server.property module .INDENT 0.0 .TP .B exception PropertiesException Bases: \fBException\fP .sp Exception for DBus properties. .UNINDENT .INDENT 0.0 .TP .B class PropertiesInterface Bases: \fBobject\fP .sp Standard DBus interface org.freedesktop.DBus.Properties. .sp DBus objects don\(aqt have to inherit this class, because the DBus library provides support for this interface by default. This class only extends this support. .sp Report the changed property: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C self.report_changed_property(\(aqX\(aq) .ft P .fi .UNINDENT .UNINDENT .sp Emit all changes when the method is done: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @emits_properties_changed def SetX(x: Int): self.set_x(x) .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B PropertiesChanged DBus signal. .sp Can be used as: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C Signal = dbus_signal() .ft P .fi .UNINDENT .UNINDENT .sp Or as a method decorator: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @dbus_signal def Signal(x: Int, y: Double): pass .ft P .fi .UNINDENT .UNINDENT .sp Signal is defined by the type hints of a decorated method. This method is accessible as: signal.definition .sp If the signal is not defined by a method, it is expected to have no arguments and signal.definition is equal to None. .UNINDENT .INDENT 7.0 .TP .B flush_changes() Flush properties changes. .UNINDENT .INDENT 7.0 .TP .B report_changed_property(property_name) Reports changed DBus property. .INDENT 7.0 .TP .B Parameters \fBproperty_name\fP \-\- a name of a DBus property .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B emits_properties_changed(method) Decorator for emitting properties changes. .sp The decorated method has to be a member of a class that inherits PropertiesInterface. .INDENT 7.0 .TP .B Parameters \fBmethod\fP \-\- a DBus method of a class that inherits PropertiesInterface .TP .B Returns a wrapper of a DBus method that emits PropertiesChanged .UNINDENT .UNINDENT .SS dasbus.server.publishable module .INDENT 0.0 .TP .B class Publishable Bases: \fBobject\fP .sp Abstract class for Python objects that can be published on DBus. .sp Example: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C # Define a publishable class. class MyObject(Publishable): def for_publication(self): return MyDBusInterface(self) # Create a publishable object. my_object = MyObject() # Publish the object on DBus. DBus.publish_object("/org/project/x", my_object.for_publication()) .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B abstract for_publication() Return a DBus representation of this object. .INDENT 7.0 .TP .B Returns an instance of @dbus_interface or @dbus_class .UNINDENT .UNINDENT .UNINDENT .SS dasbus.server.template module .INDENT 0.0 .TP .B class BasicInterfaceTemplate(implementation) Bases: \fBobject\fP .sp Basic template for a DBus interface. .sp This template uses a software design pattern called proxy. .sp This class provides a recommended way how to define DBus interfaces and create publishable DBus objects. The class that defines a DBus interface should inherit this class and be decorated with @dbus_class or @dbus_interface decorator. The implementation of this interface will be provided by a separate object called implementation. Therefore the methods of this class should call the methods of the implementation, the signals should be connected to the signals of the implementation and the getters and setters of properties should access the properties of the implementation. .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C @dbus_interface("org.myproject.X") class InterfaceX(BasicInterfaceTemplate): def DoSomething(self) \-> Str: return self.implementation.do_something() class X(object): def do_something(self): return "Done!" x = X() i = InterfaceX(x) DBus.publish_object("/org/myproject/X", i) .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B connect_signals() Interconnect the signals. .sp You should connect the emit methods of the interface signals to the signals of the implementation. Every time the implementation emits a signal, this interface reemits the signal on DBus. .UNINDENT .INDENT 7.0 .TP .B property implementation Return the implementation of this interface. .INDENT 7.0 .TP .B Returns an implementation .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class InterfaceTemplate(implementation) Bases: \fI\%dasbus.server.template.BasicInterfaceTemplate\fP, \fBdasbus.server.property.PropertiesInterface\fP .sp Template for a DBus interface. .sp The interface provides the support for the standard interface org.freedesktop.DBus.Properties. .sp Usage: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C def connect_signals(self): super().connect_signals() self.implementation.module_properties_changed.connect( self.flush_changes ) self.watch_property("X", self.implementation.x_changed) @property def X(self, x) \-> Int: return self.implementation.x @emits_properties_changed def SetX(self, x: Int): self.implementation.set_x(x) .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B watch_property(property_name, signal) Watch a DBus property. .sp Report a change when the property is changed. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBproperty_name\fP \-\- a name of a DBus property .IP \(bu 2 \fBsignal\fP \-\- a signal that emits when the property is changed .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SS dasbus.connection module .INDENT 0.0 .TP .B class AddressedMessageBus(address, *args, **kwargs) Bases: \fI\%dasbus.connection.MessageBus\fP .sp Representation of a connection for the specified address. .INDENT 7.0 .TP .B property address The bus address. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class GLibConnection Bases: \fBobject\fP .sp The low\-level DBus connection library based on GLib. .INDENT 7.0 .TP .B DEFAULT_FLAGS = .UNINDENT .INDENT 7.0 .TP .B static get_addressed_bus_connection(bus_address, flags=, observer=None, cancellable=None) Get a connection to a bus at the specified address. .UNINDENT .INDENT 7.0 .TP .B static get_session_bus_connection(cancellable=None) Get a session bus connection. .UNINDENT .INDENT 7.0 .TP .B static get_system_bus_connection(cancellable=None) Get a system bus connection. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class MessageBus(error_mapper=None, provider=) Bases: \fBdasbus.connection.AbstractMessageBus\fP .sp Representation of a message bus based on D\-Bus. .INDENT 7.0 .TP .B property connection The DBus connection. .UNINDENT .INDENT 7.0 .TP .B disconnect() Disconnect from DBus. .UNINDENT .INDENT 7.0 .TP .B get_proxy(service_name, object_path, interface_name=None, proxy_factory=None, **proxy_arguments) Returns a proxy of a remote DBus object. .sp If the proxy factory is not specified, we will use a default one. If the interface name is set, we will choose InterfaceProxy, otherwise ObjectProxy. .sp If the interface name is set, we will add it to the additional arguments for the proxy factory. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBservice_name\fP \-\- a DBus name of a service .IP \(bu 2 \fBobject_path\fP \-\- a DBus path of an object .IP \(bu 2 \fBinterface_name\fP \-\- a DBus name of an interface or None .IP \(bu 2 \fBproxy_factory\fP \-\- a factory of a DBus object proxy .IP \(bu 2 \fBproxy_arguments\fP \-\- additional arguments for the proxy factory .UNINDENT .TP .B Returns a proxy object .UNINDENT .UNINDENT .INDENT 7.0 .TP .B property proxy The proxy of DBus. .UNINDENT .INDENT 7.0 .TP .B publish_object(object_path, obj, server_factory=, **server_arguments) Publish an object on DBus. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBobject_path\fP \-\- a DBus path of an object .IP \(bu 2 \fBobj\fP \-\- an instance of @dbus_interface or @dbus_class .IP \(bu 2 \fBserver_factory\fP \-\- a factory of a DBus server object handler .IP \(bu 2 \fBserver_arguments\fP \-\- additional arguments for the server factory .UNINDENT .UNINDENT .UNINDENT .INDENT 7.0 .TP .B register_service(service_name, flags=1) Register a service on DBus. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBservice_name\fP \-\- a DBus name of a service .IP \(bu 2 \fBflags\fP \-\- the flags argument of the RequestName DBus method .UNINDENT .UNINDENT .UNINDENT .INDENT 7.0 .TP .B unpublish_object(object_path) .UNINDENT .INDENT 7.0 .TP .B unregister_service(object_path) .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class SessionMessageBus(error_mapper=None, provider=) Bases: \fI\%dasbus.connection.MessageBus\fP .sp Representation of a session bus connection. .UNINDENT .INDENT 0.0 .TP .B class SystemMessageBus(error_mapper=None, provider=) Bases: \fI\%dasbus.connection.MessageBus\fP .sp Representation of a system bus connection. .UNINDENT .SS dasbus.constants module .SS dasbus.error module .INDENT 0.0 .TP .B class AbstractErrorRule Bases: \fBobject\fP .sp Abstract rule for mapping a Python exception to a DBus error. .INDENT 7.0 .TP .B abstract get_name(exception_type) Get a DBus name for the given exception type. .INDENT 7.0 .TP .B Parameters \fBexception_type\fP \-\- a type of the Python error .TP .B Returns a name of the DBus error .UNINDENT .UNINDENT .INDENT 7.0 .TP .B abstract get_type(error_name) Get an exception type of the given DBus error. .sp param error_name: a name of the DBus error :return: a type of the Python error .UNINDENT .INDENT 7.0 .TP .B abstract match_name(error_name) Is this rule matching the given DBus error? .INDENT 7.0 .TP .B Parameters \fBerror_name\fP \-\- a name of the DBus error .TP .B Returns True or False .UNINDENT .UNINDENT .INDENT 7.0 .TP .B abstract match_type(exception_type) Is this rule matching the given exception type? .INDENT 7.0 .TP .B Parameters \fBexception_type\fP \-\- a type of the Python error .TP .B Returns True or False .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B exception DBusError Bases: \fBException\fP .sp A default DBus error. .UNINDENT .INDENT 0.0 .TP .B class DefaultErrorRule(default_type, default_namespace) Bases: \fI\%dasbus.error.AbstractErrorRule\fP .sp Default rule for mapping a Python exception to a DBus error. .INDENT 7.0 .TP .B get_name(exception_type) Get a DBus name for the given exception type. .UNINDENT .INDENT 7.0 .TP .B get_type(error_name) Get an exception type of the given DBus error. .UNINDENT .INDENT 7.0 .TP .B match_name(error_name) Is this rule matching the given DBus error? .UNINDENT .INDENT 7.0 .TP .B match_type(exception_type) Is this rule matching the given exception type? .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class ErrorMapper Bases: \fBobject\fP .sp Class for mapping Python exceptions to DBus errors. .INDENT 7.0 .TP .B add_rule(rule: dasbus.error.AbstractErrorRule) Add a rule to the error mapper. .sp The new rule will have a higher priority than the rules already contained in the error mapper. .INDENT 7.0 .TP .B Parameters \fBrule\fP (\fIan instance of AbstractErrorRule\fP) \-\- an error rule .UNINDENT .UNINDENT .INDENT 7.0 .TP .B get_error_name(exception_type) Get a DBus name of the Python exception. .sp Try to find a matching rule in the error mapper. If a rule matches the given exception type, use the rule to get the name of the DBus error. .sp The rules in the error mapper are processed in the reversed order to respect the priority of the rules. .INDENT 7.0 .TP .B Parameters \fBexception_type\fP (\fIa subclass of Exception\fP) \-\- a type of the Python error .TP .B Returns a name of the DBus error .TP .B Raises \fBLookupError\fP \-\- if no name is found .UNINDENT .UNINDENT .INDENT 7.0 .TP .B get_exception_type(error_name) Get a Python exception type of the DBus error. .sp Try to find a matching rule in the error mapper. If a rule matches the given name of a DBus error, use the rule to get the type of a Python exception. .sp The rules in the error mapper are processed in the reversed order to respect the priority of the rules. .INDENT 7.0 .TP .B Parameters \fBerror_name\fP \-\- a name of the DBus error .TP .B Returns a type of the Python exception .TP .B Return type a subclass of Exception .TP .B Raises \fBLookupError\fP \-\- if no type is found .UNINDENT .UNINDENT .INDENT 7.0 .TP .B reset_rules() Reset rules in the error mapper. .sp Reset the error rules to the initial state. All rules will be replaced with the default ones. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class ErrorRule(exception_type, error_name) Bases: \fI\%dasbus.error.AbstractErrorRule\fP .sp Rule for mapping a Python exception to a DBus error. .INDENT 7.0 .TP .B get_name(exception_type) Get a DBus name for the given exception type. .UNINDENT .INDENT 7.0 .TP .B get_type(error_name) Get an exception type of the given DBus error. .UNINDENT .INDENT 7.0 .TP .B match_name(error_name) Is this rule matching the given DBus error? .UNINDENT .INDENT 7.0 .TP .B match_type(exception_type) Is this rule matching the given exception type? .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_error_decorator(error_mapper) Generate a decorator for DBus errors. .sp Create a function for decorating Python exception classes. The decorator will add a new rule to the given error mapper that will map the class to the specified error name. .sp Definition of the decorator: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C decorator(error_name, namespace=()) .ft P .fi .UNINDENT .UNINDENT .sp The decorator accepts a name of the DBus error and optionally a namespace of the DBus name. The namespace will be used as a prefix of the DBus name. .sp Usage: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C # Create an error mapper. error_mapper = ErrorMapper() # Create a decorator for DBus errors and use it to map # the class ExampleError to the name my.example.Error. dbus_error = create_error_decorator(error_mapper) @dbus_error("my.example.Error") class ExampleError(DBusError): pass .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B Parameters \fBerror_mapper\fP \-\- an error mapper .TP .B Returns a decorator .UNINDENT .UNINDENT .SS dasbus.identifier module .INDENT 0.0 .TP .B class DBusInterfaceIdentifier(namespace, basename=None, interface_version=None) Bases: \fBdasbus.identifier.DBusBaseIdentifier\fP .sp Identifier of a DBus interface. .INDENT 7.0 .TP .B property interface_name Full name of the DBus interface. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class DBusObjectIdentifier(namespace, basename=None, interface_version=None, object_version=None) Bases: \fI\%dasbus.identifier.DBusInterfaceIdentifier\fP .sp Identifier of a DBus object. .INDENT 7.0 .TP .B property object_path Full path of the DBus object. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class DBusServiceIdentifier(message_bus, namespace, basename=None, interface_version=None, object_version=None, service_version=None) Bases: \fI\%dasbus.identifier.DBusObjectIdentifier\fP .sp Identifier of a DBus service. .INDENT 7.0 .TP .B get_proxy(object_path=None, interface_name=None, **bus_arguments) Returns a proxy of the DBus object. .sp If no object path is specified, we will use the object path of this DBus service. .sp If no interface name is specified, we will use none and create a proxy from all interfaces of the DBus object. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBobject_path\fP \-\- an object identifier or a DBus path or None .IP \(bu 2 \fBinterface_name\fP \-\- an interface identifier or a DBus name or None .IP \(bu 2 \fBbus_arguments\fP \-\- additional arguments for the message bus .UNINDENT .TP .B Returns a proxy object .UNINDENT .UNINDENT .INDENT 7.0 .TP .B property message_bus Message bus of the DBus service. .INDENT 7.0 .TP .B Returns a message bus .TP .B Return type an instance of the MessageBus class .UNINDENT .UNINDENT .INDENT 7.0 .TP .B property service_name Full name of a DBus service. .UNINDENT .UNINDENT .SS dasbus.loop module .INDENT 0.0 .TP .B class AbstractEventLoop Bases: \fBobject\fP .sp The abstract representation of the event loop. .sp It is necessary to run the event loop to handle emitted DBus signals or incoming DBus calls (in the DBus service). .sp Example: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C # Create the event loop. loop = EventLoop() # Start the event loop. loop.run() # Run loop.quit() to stop. .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B abstract quit() Stop the event loop. .UNINDENT .INDENT 7.0 .TP .B abstract run() Start the event loop. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class EventLoop Bases: \fI\%dasbus.loop.AbstractEventLoop\fP .sp The representation of the event loop. .INDENT 7.0 .TP .B quit() Stop the event loop. .UNINDENT .INDENT 7.0 .TP .B run() Start the event loop. .UNINDENT .UNINDENT .SS dasbus.namespace module .INDENT 0.0 .TP .B get_dbus_name(*namespace) Create a DBus name from the given names. .INDENT 7.0 .TP .B Parameters \fBnamespace\fP \-\- a sequence of names .TP .B Returns a DBus name .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_dbus_path(*namespace) Create a DBus path from the given names. .INDENT 7.0 .TP .B Parameters \fBnamespace\fP \-\- a sequence of names .TP .B Returns a DBus path .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_namespace_from_name(name) Return a namespace of the DBus name. .INDENT 7.0 .TP .B Parameters \fBname\fP \-\- a DBus name .TP .B Returns a sequence of names .UNINDENT .UNINDENT .SS dasbus.signal module .INDENT 0.0 .TP .B class Signal Bases: \fBobject\fP .sp Default representation of a signal. .INDENT 7.0 .TP .B connect(callback) Connect to a signal. .INDENT 7.0 .TP .B Parameters \fBcallback\fP \-\- a function to register .UNINDENT .UNINDENT .INDENT 7.0 .TP .B disconnect(callback=None) Disconnect from a signal. .sp If no callback is specified, then all functions will be unregistered from the signal. .sp If the specified callback isn\(aqt registered, do nothing. .INDENT 7.0 .TP .B Parameters \fBcallback\fP \-\- a function to unregister or None .UNINDENT .UNINDENT .INDENT 7.0 .TP .B emit(*args, **kwargs) Emit a signal with the given arguments. .UNINDENT .UNINDENT .SS dasbus.specification module .INDENT 0.0 .TP .B class DBusSpecification Bases: \fBobject\fP .sp DBus XML specification. .INDENT 7.0 .TP .B ACCESS_READ = \(aqread\(aq .UNINDENT .INDENT 7.0 .TP .B ACCESS_READWRITE = \(aqreadwrite\(aq .UNINDENT .INDENT 7.0 .TP .B ACCESS_WRITE = \(aqwrite\(aq .UNINDENT .INDENT 7.0 .TP .B DIRECTION_IN = \(aqin\(aq .UNINDENT .INDENT 7.0 .TP .B DIRECTION_OUT = \(aqout\(aq .UNINDENT .INDENT 7.0 .TP .B class Method(name, interface_name, in_type, out_type) Bases: \fBtuple\fP .INDENT 7.0 .TP .B in_type Alias for field number 2 .UNINDENT .INDENT 7.0 .TP .B interface_name Alias for field number 1 .UNINDENT .INDENT 7.0 .TP .B name Alias for field number 0 .UNINDENT .INDENT 7.0 .TP .B out_type Alias for field number 3 .UNINDENT .UNINDENT .INDENT 7.0 .TP .B class Property(name, interface_name, readable, writable, type) Bases: \fBtuple\fP .INDENT 7.0 .TP .B interface_name Alias for field number 1 .UNINDENT .INDENT 7.0 .TP .B name Alias for field number 0 .UNINDENT .INDENT 7.0 .TP .B readable Alias for field number 2 .UNINDENT .INDENT 7.0 .TP .B type Alias for field number 4 .UNINDENT .INDENT 7.0 .TP .B writable Alias for field number 3 .UNINDENT .UNINDENT .INDENT 7.0 .TP .B RETURN_PARAMETER = \(aqreturn\(aq .UNINDENT .INDENT 7.0 .TP .B STANDARD_INTERFACES = \(aq\en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \en \(aq .UNINDENT .INDENT 7.0 .TP .B class Signal(name, interface_name, type) Bases: \fBtuple\fP .INDENT 7.0 .TP .B interface_name Alias for field number 1 .UNINDENT .INDENT 7.0 .TP .B name Alias for field number 0 .UNINDENT .INDENT 7.0 .TP .B type Alias for field number 2 .UNINDENT .UNINDENT .INDENT 7.0 .TP .B add_member(member) Add a member of a DBus interface. .UNINDENT .INDENT 7.0 .TP .B classmethod from_xml(xml) Return a DBus specification for the given XML. .UNINDENT .INDENT 7.0 .TP .B get_member(interface_name, member_name) Get a member of a DBus interface. .UNINDENT .INDENT 7.0 .TP .B property interfaces Interfaces of the DBus specification. .UNINDENT .INDENT 7.0 .TP .B property members Members of the DBus specification. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B exception DBusSpecificationError Bases: \fBException\fP .sp Exception for the DBus specification errors. .UNINDENT .INDENT 0.0 .TP .B class DBusSpecificationParser Bases: \fBobject\fP .sp Class for parsing DBus XML specification. .INDENT 7.0 .TP .B classmethod parse_specification(xml, factory=) Generate a representation of a DBus XML specification. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBxml\fP \-\- the XML specification to parse .IP \(bu 2 \fBfactory\fP \-\- the DBus specification factory .UNINDENT .TP .B Returns a representation od the DBus specification .UNINDENT .UNINDENT .INDENT 7.0 .TP .B xml_parser alias of \fBdasbus.xml.XMLParser\fP .UNINDENT .UNINDENT .SS dasbus.structure module .INDENT 0.0 .TP .B class DBusData Bases: \fBobject\fP .sp Object representation of data in a DBus structure. .sp Classes derived from this class should represent specific types of DBus structures. They will support a conversion from a DBus structure of this type to a Python object and back. .INDENT 7.0 .TP .B classmethod from_structure(structure: Dict[str, gi.overrides.GLib.Variant]) Convert a DBus structure to a data object. .INDENT 7.0 .TP .B Parameters \fBstructure\fP \-\- a DBus structure .TP .B Returns a data object .UNINDENT .UNINDENT .INDENT 7.0 .TP .B classmethod from_structure_list(structures: List[Dict[str, gi.overrides.GLib.Variant]]) Convert DBus structures to data objects. .INDENT 7.0 .TP .B Parameters \fBstructures\fP \-\- a list of DBus structures .TP .B Returns a list of data objects .UNINDENT .UNINDENT .INDENT 7.0 .TP .B classmethod to_structure(data) -> Dict[str, gi.overrides.GLib.Variant] Convert this data object to a DBus structure. .INDENT 7.0 .TP .B Returns a DBus structure .UNINDENT .UNINDENT .INDENT 7.0 .TP .B classmethod to_structure_list(objects) -> List[Dict[str, gi.overrides.GLib.Variant]] Convert data objects to DBus structures. .INDENT 7.0 .TP .B Parameters \fBobjects\fP \-\- a list of data objects .TP .B Returns a list of DBus structures .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B exception DBusStructureError Bases: \fBException\fP .sp General exception for DBus structure errors. .UNINDENT .INDENT 0.0 .TP .B compare_data(obj, other) Compare data of the given data objects. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBobj\fP \-\- a data object .IP \(bu 2 \fBother\fP \-\- another data object .UNINDENT .TP .B Returns True if the data is equal, otherwise False .UNINDENT .UNINDENT .INDENT 0.0 .TP .B generate_string_from_data(obj, skip=None, add=None) Generate a string representation of a data object. .sp Set the argument \(aqskip\(aq to skip attributes with sensitive data. .sp Set the argument \(aqadd\(aq to add other values to the string representation. The attributes in the string representation will be sorted alphabetically. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBobj\fP \-\- a data object .IP \(bu 2 \fBskip\fP \-\- a list of names that should be skipped or None .IP \(bu 2 \fBadd\fP \-\- a dictionary of attributes to add or None .UNINDENT .TP .B Returns a string representation of the data object .UNINDENT .UNINDENT .SS dasbus.typing module .INDENT 0.0 .TP .B Bool alias of \fBbool\fP .UNINDENT .INDENT 0.0 .TP .B Byte(x) .UNINDENT .INDENT 0.0 .TP .B Double alias of \fBfloat\fP .UNINDENT .INDENT 0.0 .TP .B Int alias of \fBint\fP .UNINDENT .INDENT 0.0 .TP .B Int16(x) .UNINDENT .INDENT 0.0 .TP .B Int32(x) .UNINDENT .INDENT 0.0 .TP .B Int64(x) .UNINDENT .INDENT 0.0 .TP .B ObjPath(x) .UNINDENT .INDENT 0.0 .TP .B Str alias of \fBstr\fP .UNINDENT .INDENT 0.0 .TP .B UInt16(x) .UNINDENT .INDENT 0.0 .TP .B UInt32(x) .UNINDENT .INDENT 0.0 .TP .B UInt64(x) .UNINDENT .INDENT 0.0 .TP .B UnixFD(x) .UNINDENT .INDENT 0.0 .TP .B class Variant(format_string, value) Bases: \fBgi.repository.GLib.Variant\fP .INDENT 7.0 .TP .B Constructors .UNINDENT .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C new_array(child_type:GLib.VariantType=None, children:list=None) \-> GLib.Variant new_boolean(value:bool) \-> GLib.Variant new_byte(value:int) \-> GLib.Variant new_bytestring(string:list) \-> GLib.Variant new_bytestring_array(strv:list) \-> GLib.Variant new_dict_entry(key:GLib.Variant, value:GLib.Variant) \-> GLib.Variant new_double(value:float) \-> GLib.Variant new_fixed_array(element_type:GLib.VariantType, elements=None, n_elements:int, element_size:int) \-> GLib.Variant new_from_bytes(type:GLib.VariantType, bytes:GLib.Bytes, trusted:bool) \-> GLib.Variant new_from_data(type:GLib.VariantType, data:list, trusted:bool, notify:GLib.DestroyNotify, user_data=None) \-> GLib.Variant new_handle(value:int) \-> GLib.Variant new_int16(value:int) \-> GLib.Variant new_int32(value:int) \-> GLib.Variant new_int64(value:int) \-> GLib.Variant new_maybe(child_type:GLib.VariantType=None, child:GLib.Variant=None) \-> GLib.Variant new_object_path(object_path:str) \-> GLib.Variant new_objv(strv:list) \-> GLib.Variant new_signature(signature:str) \-> GLib.Variant new_string(string:str) \-> GLib.Variant new_strv(strv:list) \-> GLib.Variant new_tuple(children:list) \-> GLib.Variant new_uint16(value:int) \-> GLib.Variant new_uint32(value:int) \-> GLib.Variant new_uint64(value:int) \-> GLib.Variant new_variant(value:GLib.Variant) \-> GLib.Variant .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B get_string(self) -> str, length:int .UNINDENT .INDENT 7.0 .TP .B keys() .UNINDENT .INDENT 7.0 .TP .B static new_tuple(children: list) -> GLib.Variant .UNINDENT .INDENT 7.0 .TP .B classmethod split_signature(signature) Return a list of the element signatures of the topmost signature tuple. .sp If the signature is not a tuple, it returns one element with the entire signature. If the signature is an empty tuple, the result is []. .sp This is useful for e. g. iterating over method parameters which are passed as a single Variant. .UNINDENT .INDENT 7.0 .TP .B unpack() Decompose a GVariant into a native Python object. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class VariantType(**kwargs) Bases: \fBgi.Boxed\fP .INDENT 7.0 .TP .B Constructors .UNINDENT .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C new(type_string:str) \-> GLib.VariantType new_array(element:GLib.VariantType) \-> GLib.VariantType new_dict_entry(key:GLib.VariantType, value:GLib.VariantType) \-> GLib.VariantType new_maybe(element:GLib.VariantType) \-> GLib.VariantType new_tuple(items:list) \-> GLib.VariantType .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B checked_ = gi.FunctionInfo(checked_) .UNINDENT .INDENT 7.0 .TP .B copy = gi.FunctionInfo(copy) .UNINDENT .INDENT 7.0 .TP .B dup_string = gi.FunctionInfo(dup_string) .UNINDENT .INDENT 7.0 .TP .B element = gi.FunctionInfo(element) .UNINDENT .INDENT 7.0 .TP .B equal = gi.FunctionInfo(equal) .UNINDENT .INDENT 7.0 .TP .B first = gi.FunctionInfo(first) .UNINDENT .INDENT 7.0 .TP .B free = gi.FunctionInfo(free) .UNINDENT .INDENT 7.0 .TP .B get_string_length = gi.FunctionInfo(get_string_length) .UNINDENT .INDENT 7.0 .TP .B hash = gi.FunctionInfo(hash) .UNINDENT .INDENT 7.0 .TP .B is_array = gi.FunctionInfo(is_array) .UNINDENT .INDENT 7.0 .TP .B is_basic = gi.FunctionInfo(is_basic) .UNINDENT .INDENT 7.0 .TP .B is_container = gi.FunctionInfo(is_container) .UNINDENT .INDENT 7.0 .TP .B is_definite = gi.FunctionInfo(is_definite) .UNINDENT .INDENT 7.0 .TP .B is_dict_entry = gi.FunctionInfo(is_dict_entry) .UNINDENT .INDENT 7.0 .TP .B is_maybe = gi.FunctionInfo(is_maybe) .UNINDENT .INDENT 7.0 .TP .B is_subtype_of = gi.FunctionInfo(is_subtype_of) .UNINDENT .INDENT 7.0 .TP .B is_tuple = gi.FunctionInfo(is_tuple) .UNINDENT .INDENT 7.0 .TP .B is_variant = gi.FunctionInfo(is_variant) .UNINDENT .INDENT 7.0 .TP .B key = gi.FunctionInfo(key) .UNINDENT .INDENT 7.0 .TP .B n_items = gi.FunctionInfo(n_items) .UNINDENT .INDENT 7.0 .TP .B new = gi.FunctionInfo(new) .UNINDENT .INDENT 7.0 .TP .B new_array = gi.FunctionInfo(new_array) .UNINDENT .INDENT 7.0 .TP .B new_dict_entry = gi.FunctionInfo(new_dict_entry) .UNINDENT .INDENT 7.0 .TP .B new_maybe = gi.FunctionInfo(new_maybe) .UNINDENT .INDENT 7.0 .TP .B new_tuple = gi.FunctionInfo(new_tuple) .UNINDENT .INDENT 7.0 .TP .B next = gi.FunctionInfo(next) .UNINDENT .INDENT 7.0 .TP .B string_get_depth_ = gi.FunctionInfo(string_get_depth_) .UNINDENT .INDENT 7.0 .TP .B string_is_valid = gi.FunctionInfo(string_is_valid) .UNINDENT .INDENT 7.0 .TP .B string_scan = gi.FunctionInfo(string_scan) .UNINDENT .INDENT 7.0 .TP .B value = gi.FunctionInfo(value) .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class VariantUnpacker Bases: \fI\%dasbus.typing.VariantUnpacking\fP .sp Class for unpacking variants. .INDENT 7.0 .TP .B classmethod apply(variant) Unpack the specified variant. .INDENT 7.0 .TP .B Parameters \fBvariant\fP \-\- a variant to unpack .TP .B Returns an unpacked value .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class VariantUnpacking Bases: \fBobject\fP .sp Set of functions of unpacking a variant. .sp This class is doing the same as the unpack method of the Variant class, but it allows to reuse the code for other variant modifications. .UNINDENT .INDENT 0.0 .TP .B class VariantUnwrapper Bases: \fI\%dasbus.typing.VariantUnpacking\fP .sp Class for unwrapping variants. .INDENT 7.0 .TP .B classmethod apply(variant) Unwrap the specified variant. .INDENT 7.0 .TP .B Parameters \fBvariant\fP \-\- a variant to unwrap .TP .B Returns a unwrapped value .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_dbus_type(type_hint) Return DBus representation of a type hint. .INDENT 7.0 .TP .B Parameters \fBtype_hint\fP \-\- a type hint .TP .B Returns a string with DBus representation .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_native(value) Decompose a DBus value into a native Python object. .sp This function is useful for testing, when the DBus library doesn\(aqt decompose arguments and return values of DBus calls. .INDENT 7.0 .TP .B Parameters \fBvalue\fP \-\- a DBus value .TP .B Returns a native Python object .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_type_arguments(type_hint) Get the arguments of the type hint. .sp For example, Str and Int are arguments of the type hint Tuple(Str, Int). .INDENT 7.0 .TP .B Parameters \fBtype_hint\fP \-\- a type hint .TP .B Returns a type arguments .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_variant(type_hint, value) Return a variant data type. .sp The type of a variant is specified with a type hint. .sp Example: .INDENT 7.0 .INDENT 3.5 .sp .nf .ft C v1 = get_variant(Bool, True) v2 = get_variant(List[Int], [1,2,3]) .ft P .fi .UNINDENT .UNINDENT .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBtype_hint\fP \-\- a type hint or a type string .IP \(bu 2 \fBvalue\fP \-\- a value of the variant .UNINDENT .TP .B Returns an instance of Variant .UNINDENT .UNINDENT .INDENT 0.0 .TP .B get_variant_type(type_hint) Return a type of a variant data type. .INDENT 7.0 .TP .B Parameters \fBtype_hint\fP \-\- a type hint or a type string .TP .B Returns an instance of VariantType .UNINDENT .UNINDENT .INDENT 0.0 .TP .B is_base_type(type_hint, base_type) Is the given base type a base of the specified type hint? .sp For example, List is a base of the type hint List[Int] and Int is a base of the type hint Int. A class is a base of itself and of every subclass of this class. .INDENT 7.0 .TP .B Parameters .INDENT 7.0 .IP \(bu 2 \fBtype_hint\fP \-\- a type hint .IP \(bu 2 \fBbase_type\fP \-\- a base type .UNINDENT .TP .B Returns True or False .UNINDENT .UNINDENT .INDENT 0.0 .TP .B is_tuple_of_one(type_hint) Is the type hint a tuple of one item? .INDENT 7.0 .TP .B Parameters \fBtype_hint\fP \-\- a type hint or a type string .TP .B Returns True or False .UNINDENT .UNINDENT .INDENT 0.0 .TP .B unwrap_variant(variant) Unwrap a variant data type. .sp Unlike the unpack method of the Variant class, this function doesn\(aqt recursively unpacks all variants in the data structure. It will unpack only the topmost variant. .sp The implementation is inspired by the unpack method. .INDENT 7.0 .TP .B Parameters \fBvariant\fP \-\- a variant .TP .B Returns a value .UNINDENT .UNINDENT .SS dasbus.xml module .INDENT 0.0 .TP .B class XMLGenerator Bases: \fI\%dasbus.xml.XMLParser\fP .sp Class for generating XML. .INDENT 7.0 .TP .B static add_child(parent_element, child_element) Append the child element to the parent element. .UNINDENT .INDENT 7.0 .TP .B static add_comment(element, comment) .UNINDENT .INDENT 7.0 .TP .B static create_interface(name) Create an interface element. .UNINDENT .INDENT 7.0 .TP .B static create_method(name) Create a method element. .UNINDENT .INDENT 7.0 .TP .B static create_node() Create a node element called node. .UNINDENT .INDENT 7.0 .TP .B static create_parameter(name, param_type, direction) Create a parameter element. .UNINDENT .INDENT 7.0 .TP .B static create_property(name, property_type, access) Create a property element. .UNINDENT .INDENT 7.0 .TP .B static create_signal(name) Create a signal element. .UNINDENT .INDENT 7.0 .TP .B static element_to_xml(element) Return XML of the element. .UNINDENT .INDENT 7.0 .TP .B static prettify_xml(xml) Return pretty printed normalized XML. .sp Python 3.8 changed the order of the attributes and introduced the function canonicalize that should be used to normalize XML. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class XMLParser Bases: \fBobject\fP .sp Class for parsing XML. .INDENT 7.0 .TP .B static get_access(node) .UNINDENT .INDENT 7.0 .TP .B static get_direction(node) .UNINDENT .INDENT 7.0 .TP .B static get_interfaces_from_node(node_element) Return a dictionary of interfaces defined in a node element. .UNINDENT .INDENT 7.0 .TP .B static get_name(node) .UNINDENT .INDENT 7.0 .TP .B static get_type(node) .UNINDENT .INDENT 7.0 .TP .B static has_name(node, node_name) .UNINDENT .INDENT 7.0 .TP .B static is_interface(member_node) .UNINDENT .INDENT 7.0 .TP .B static is_member(member_node) .UNINDENT .INDENT 7.0 .TP .B static is_method(member_node) .UNINDENT .INDENT 7.0 .TP .B static is_parameter(member_node) .UNINDENT .INDENT 7.0 .TP .B static is_property(member_node) .UNINDENT .INDENT 7.0 .TP .B static is_signal(member_node) .UNINDENT .INDENT 7.0 .TP .B static xml_to_element(xml) .UNINDENT .UNINDENT .SS Examples .sp Look at the \fI\%complete examples\fP or \fI\%DBus services\fP of the Anaconda Installer for more inspiration. .SS Basic usage .sp Show the current hostname. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.connection import SystemMessageBus bus = SystemMessageBus() proxy = bus.get_proxy( "org.freedesktop.hostname1", "/org/freedesktop/hostname1" ) print(proxy.Hostname) .ft P .fi .UNINDENT .UNINDENT .sp Send a notification to the notification server. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.connection import SessionMessageBus bus = SessionMessageBus() proxy = bus.get_proxy( "org.freedesktop.Notifications", "/org/freedesktop/Notifications" ) id = proxy.Notify( "", 0, "face\-smile", "Hello World!", "This notification can be ignored.", [], {}, 0 ) print("The notification {} was sent.".format(id)) .ft P .fi .UNINDENT .UNINDENT .sp Handle a closed notification. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.loop import EventLoop loop = EventLoop() from dasbus.connection import SessionMessageBus bus = SessionMessageBus() proxy = bus.get_proxy( "org.freedesktop.Notifications", "/org/freedesktop/Notifications" ) def callback(id, reason): print("The notification {} was closed.".format(id)) proxy.NotificationClosed.connect(callback) loop.run() .ft P .fi .UNINDENT .UNINDENT .sp Asynchronously fetch a list of network devices. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.loop import EventLoop loop = EventLoop() from dasbus.connection import SystemMessageBus bus = SystemMessageBus() proxy = bus.get_proxy( "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager" ) def callback(call): print(call()) proxy.GetDevices(callback=callback) loop.run() .ft P .fi .UNINDENT .UNINDENT .sp Define the org.example.HelloWorld service. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C class HelloWorld(object): __dbus_xml__ = """ """ def Hello(self, name): return "Hello {}!".format(name) .ft P .fi .UNINDENT .UNINDENT .sp Define the org.example.HelloWorld service with an automatically generated XML specification. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.server.interface import dbus_interface from dasbus.typing import Str @dbus_interface("org.example.HelloWorld") class HelloWorld(object): def Hello(self, name: Str) \-> Str: return "Hello {}!".format(name) print(HelloWorld.__dbus_xml__) .ft P .fi .UNINDENT .UNINDENT .sp Publish the org.example.HelloWorld service on the session message bus. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.connection import SessionMessageBus bus = SessionMessageBus() bus.publish_object("/org/example/HelloWorld", HelloWorld()) bus.register_service("org.example.HelloWorld") from dasbus.loop import EventLoop loop = EventLoop() loop.run() .ft P .fi .UNINDENT .UNINDENT .SS Support for Unix file descriptors .sp The support for Unix file descriptors is disabled by default. It needs to be explicitly enabled when you create a DBus proxy or publish a DBus object that could send or receive Unix file descriptors. .sp \fBWARNING:\fP .INDENT 0.0 .INDENT 3.5 This functionality is supported only on UNIX. .UNINDENT .UNINDENT .sp Send and receive Unix file descriptors with a DBus proxy. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C import os from dasbus.connection import SystemMessageBus from dasbus.unix import GLibClientUnix bus = SystemMessageBus() proxy = bus.get_proxy( "org.freedesktop.login1", "/org/freedesktop/login1", client=GLibClientUnix ) fd = proxy.Inhibit( "sleep", "my\-example", "Running an example", "block" ) proxy.ListInhibitors() os.close(fd) .ft P .fi .UNINDENT .UNINDENT .sp Allow to send and receive Unix file descriptors within the /org/example/HelloWorld DBus object. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.unix import GLibServerUnix bus.publish_object( "/org/example/HelloWorld", HelloWorld(), server=GLibServerUnix ) .ft P .fi .UNINDENT .UNINDENT .SS Management of DBus names and paths .sp Use constants to define DBus services and objects. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.connection import SystemMessageBus from dasbus.identifier import DBusServiceIdentifier, DBusObjectIdentifier NETWORK_MANAGER_NAMESPACE = ( "org", "freedesktop", "NetworkManager" ) NETWORK_MANAGER = DBusServiceIdentifier( namespace=NETWORK_MANAGER_NAMESPACE, message_bus=SystemMessageBus() ) NETWORK_MANAGER_SETTINGS = DBusObjectIdentifier( namespace=NETWORK_MANAGER_NAMESPACE, basename="Settings" ) .ft P .fi .UNINDENT .UNINDENT .sp Create a proxy of the org.freedesktop.NetworkManager service. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C proxy = NETWORK_MANAGER.get_proxy() print(proxy.NetworkingEnabled) .ft P .fi .UNINDENT .UNINDENT .sp Create a proxy of the /org/freedesktop/NetworkManager/Settings object. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C proxy = NETWORK_MANAGER.get_proxy(NETWORK_MANAGER_SETTINGS) print(proxy.Hostname) .ft P .fi .UNINDENT .UNINDENT .sp See \fI\%a complete example\fP\&. .SS Error handling .sp Use exceptions to propagate and handle DBus errors. Create an error mapper and a decorator for mapping Python exception classes to DBus error names. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.error import ErrorMapper, DBusError, get_error_decorator error_mapper = ErrorMapper() dbus_error = get_error_decorator(error_mapper) .ft P .fi .UNINDENT .UNINDENT .sp Use the decorator to register Python exceptions that represent DBus errors. These exceptions can be raised by DBus services and caught by DBus clients in the try\-except block. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C @dbus_error("org.freedesktop.DBus.Error.InvalidArgs") class InvalidArgs(DBusError): pass .ft P .fi .UNINDENT .UNINDENT .sp The message bus will use the specified error mapper to automatically transform Python exceptions to DBus errors and back. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.connection import SessionMessageBus bus = SessionMessageBus(error_mapper=error_mapper) .ft P .fi .UNINDENT .UNINDENT .sp See \fI\%a complete example\fP\&. .SS Timeout for a DBus call .sp Call DBus methods with a timeout (specified in milliseconds). .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C proxy = NETWORK_MANAGER.get_proxy() try: proxy.CheckConnectivity(timeout=3) except TimeoutError: print("The call timed out!") .ft P .fi .UNINDENT .UNINDENT .SS Support for DBus structures .sp Represent DBus structures by Python objects. A DBus structure is a dictionary of attributes that maps attribute names to variants with attribute values. Use Python objects to define such structures. They can be easily converted to a dictionary, send via DBus and converted back to an object. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.structure import DBusData from dasbus.typing import Str, get_variant class UserData(DBusData): def __init__(self): self._name = "" @property def name(self) \-> Str: return self._name @name.setter def name(self, name): self._name = name data = UserData() data.name = "Alice" print(UserData.to_structure(data)) print(UserData.from_structure({ "name": get_variant(Str, "Bob") })) .ft P .fi .UNINDENT .UNINDENT .sp See \fI\%a complete example\fP\&. .SS Management of dynamic DBus objects .sp Create Python objects that can be automatically published on DBus. These objects are usually managed by DBus containers and published on demand. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.server.interface import dbus_interface from dasbus.server.template import InterfaceTemplate from dasbus.server.publishable import Publishable from dasbus.typing import Str @dbus_interface("org.example.Chat") class ChatInterface(InterfaceTemplate): def Send(self, message: Str): return self.implementation.send() class Chat(Publishable): def for_publication(self): return ChatInterface(self) def send(self, message): print(message) .ft P .fi .UNINDENT .UNINDENT .sp Use DBus containers to automatically publish dynamically created Python objects. A DBus container converts publishable Python objects into DBus paths and back. It generates unique DBus paths in the specified namespace and assigns them to objects. Each object is published when its DBus path is requested for the first time. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C from dasbus.connection import SessionMessageBus from dasbus.server.container import DBusContainer container = DBusContainer( namespace=("org", "example", "Chat"), message_bus=SessionMessageBus() ) print(container.to_object_path(Chat())) .ft P .fi .UNINDENT .UNINDENT .sp See \fI\%a complete example\fP\&. .SH INDICES AND TABLES .INDENT 0.0 .IP \(bu 2 genindex .IP \(bu 2 modindex .IP \(bu 2 search .UNINDENT .SH AUTHOR Vendula Poncova .SH COPYRIGHT 2022, Vendula Poncova .\" Generated by docutils manpage writer. .