API Reference¶
D-Car main API.
This should normally be enough for implementing message bus clients.
Overview¶
| Representation of a client’s connection to a message bus. | |
| Match rule for signals. | |
| A D-Bus Variant. | |
| Wrapper for a unix file descriptor. | |
| An instance of this class is a proxy for an object on the D-Bus. | |
| Base class. | |
| Raised for errors in server addresses. | |
| Raised when authentication failed. | |
| Raised for transport related errors. | |
| Raised when validation failed. | |
| Raised when a signal or method could not be registered. | |
| Raised for errors in messages. | |
| Raised for errors from ERROR messages. | |
| Raised for errors in signatures. | |
| Raised when a message, an array, a name etc. | 
- 
class dcar.Bus(address='session')[source]¶
- Bases: - object- Representation of a client’s connection to a message bus. - An instance of this class is the central point for a client to interact with a message bus. It can be used as a context manager. On entering the runtime context the - connect()method will be called, on exiting the- disconnect()method.- 
property address¶
- Return the actual address the client is connected to. 
 - 
property bus_type¶
- Return the bus type: - 'system',- 'session', or- None.- New in version 0.3.0. 
 - 
property connected¶
- Return whether the client is connected. 
 - 
property unique_name¶
- Return the unique name of the client’s connection. 
 - 
property guid¶
- Return the GUID of the server. 
 - 
property unix_fds_enabled¶
- Return whether passing of unix file descriptors is enabled. 
 - 
property error¶
- Return transport error or - None.- This error is set when the client loses the connection to the message bus because of this error. 
 - 
connect()[source]¶
- Connect to message bus. - Raises
- AuthenticationError – if authentication failed 
- OSError – if connection failed 
 
 
 - 
block(timeout=None)[source]¶
- Blocks until - send-loopand- recv-loopare finished or timeout is reached.- The - send-loopand- recv-loopthreads are started when connecting to the D-Bus.- Parameters
- timeout (float) – timeout value in seconds ( - Nonemeans no timeout)
 - Changed in version 0.2.0: Add parameter - timeout
 - 
send_message(msg, timeout=None)[source]¶
- Send a message. - Normally - method_call(),- method_return(),- send_error()or- emit_signal()should be used.- Parameters
- Returns
- return values of the message call if a reply is expected else - None
- Return type
- Raises
- TransportError – if the message could not be sent 
 
 - 
method_call(object_path, interface, method_name, destination, *, sender=None, signature=None, args=(), timeout=25.0, no_auto_start=False, allow_interactive_authorization=False)[source]¶
- Send a message of type METHOD_CALL. - Parameters
- object_path (str) – object path (required) 
- interface (str) – interface name 
- method_name (str) – method name (required) 
- destination (str) – name of the destination’s connection 
- sender (str) – name of the sender’s connection 
- signature (str) – D-Bus types signature of the IN arguments 
- args (tuple) – the IN arguments 
- timeout (float) – - None= no timeout,- 0= no reply expected and- > 0= timeout in seconds
- no_auto_start (bool) – header flag 
- allow_interactive_authorization (bool) – header flag 
 
- Returns
- return values of the method call if a reply is expected else - None
- Return type
- Raises
- TransportError – if the message could not be sent 
 
 - 
method_return(reply_serial, destination, *, sender=None, signature=None, args=())[source]¶
- Send a message of type METHOD_RETURN. - Parameters
- reply_serial (int) – serial of the message for which this is a reply (required) 
- destination (str) – name of the destination’s connection 
- sender (str) – name of the sender’s connection 
- signature (str) – D-Bus types signature of the OUT arguments of the called method 
- args (tuple) – the OUT arguments of the called method 
 
- Raises
- TransportError – if the message could not be sent 
 
 - 
send_error(error_name, reply_serial, destination, *, sender=None, signature=None, args=())[source]¶
- Send a message of type ERROR. - Parameters
- error_name (str) – error name (required) 
- reply_serial (int) – serial of the message for which this is a reply (required) 
- destination (str) – name of the destination’s connection 
- sender (str) – name of the sender’s connection 
- signature (str) – D-Bus types signature of the arguments 
- args (tuple) – the arguments 
 
- Raises
- TransportError – if the message could not be sent 
 
 - 
emit_signal(object_path, interface, signal_name, destination=None, *, sender=None, signature=None, args=())[source]¶
- Send a message of type SIGNAL. - Parameters
- object_path (str) – object path (required) 
- interface (str) – interface name (required) 
- signal_name (str) – signal name (required) 
- destination (str) – name of the destination’s connection 
- sender (str) – name of the sender’s connection 
- signature (str) – D-Bus types signature of the arguments 
- args (tuple) – the arguments 
 
- Raises
- TransportError – if the message could not be sent 
 
 - 
register_signal(rule, handler, unicast=False, timeout=25.0)[source]¶
- Register a signal. - The handler function must take one parameter: a - MessageInfoobject.- Note - The handler functions for incoming method calls and signals will be executed in a separate thread sequentially. - Parameters
- Returns
- ID of the signal 
- Return type
- Raises
- RegisterError – if the signal could not be registered 
- TransportError – if the AddMatch message could not be sent 
 
 
 - 
unregister_signal(reg_id, timeout=25.0)[source]¶
- Unregister a signal. - Parameters
- reg_id (int) – ID returned by - register_signal()
- timeout (float) – timeout in seconds 
 
- Raises
- TransportError – if RemoveMatch message could not be sent 
 
 - 
register_method(object_path, interface, method_name, handler, signature=None)[source]¶
- Register a method. - The handler function must take two parameters: a - Busobject and a- MessageInfoobject.- Note - The handler functions for incoming method calls and signals will be executed in a separate thread sequentially. 
 - 
unregister_method(meth_id)[source]¶
- Unregister a method. - Parameters
- meth_id (int) – ID returned by - register_method()
 
 
- 
property 
- 
class dcar.MatchRule(object_path: str = None, interface: str = None, signal_name: str = None, sender: str = None, path_namespace: str = None, destination: str = None, arg0namespace: str = None)[source]¶
- Bases: - object- Match rule for signals. - All parameters are explained in the D-Bus specification. 
- 
class dcar.Variant(signature, value)¶
- Bases: - tuple- A D-Bus Variant. - 
signature¶
- D-Bus type signature 
 - 
value¶
- value of the Variant 
 
- 
- 
class dcar.UnixFD(f, close=False)[source]¶
- Bases: - object- Wrapper for a unix file descriptor. - The file descriptor will be - duplicated. The caller is responsible for closing the original file descriptor.- Parameters
 
- 
class dcar.RemoteObject(bus, name, path, xml=None)[source]¶
- Bases: - object- An instance of this class is a proxy for an object on the D-Bus. - Methods, signals, and properties can be accessed as attributes with the same names as on the D-Bus. If a name occurs in more than one interface, only one method, signal, or property can be accessed as an attribute. To access the shadowed names subscription syntax must be used: - obj['interface name', 'member name'].- Calling methods and accessing properties (depending on the access attribute) is done in the normal way: - obj.SomeMethod()(returns a single value, a tuple or- None)
- obj.SomeProperty(only with read access)
- obj.SomeProperty = value(only with write access)
 - Signal handlers can be set by assigning a function that takes a - MessageInfoobject as its only argument:- obj.SomeSignal = function. The handler can be removed by assigning- None.- See also: Types summary - Parameters
- Raises
- RuntimeError – if - busis not a connected- dcar.Busobject
- ValidationError – if - nameor- pathare not valid
 
 - 
property xml¶
- Return XML data. 
 
- 
exception dcar.AddressError[source]¶
- Bases: - dcar.errors.Error- Raised for errors in server addresses. 
- 
exception dcar.AuthenticationError[source]¶
- Bases: - dcar.errors.Error- Raised when authentication failed. 
- 
exception dcar.TransportError[source]¶
- Bases: - dcar.errors.Error- Raised for transport related errors. 
- 
exception dcar.ValidationError[source]¶
- Bases: - dcar.errors.Error- Raised when validation failed. 
- 
exception dcar.RegisterError[source]¶
- Bases: - dcar.errors.Error- Raised when a signal or method could not be registered. 
- 
exception dcar.MessageError[source]¶
- Bases: - dcar.errors.Error- Raised for errors in messages. 
- 
exception dcar.DBusError[source]¶
- Bases: - dcar.errors.MessageError- Raised for errors from ERROR messages. 
- 
exception dcar.SignatureError[source]¶
- Bases: - dcar.errors.MessageError- Raised for errors in signatures. 
- 
exception dcar.TooLongError[source]¶
- Bases: - dcar.errors.MessageError- Raised when a message, an array, a name etc. is too long.