Modules

dcar.address

Server Addresses.

class dcar.address.Address(address='session')[source]

Bases: object

This class represents addresses of a message bus.

See also:

An Address object can be used as an iterator which yields tuples with the first element being the name of a transport and the second a dict with the parameters.

Parameters

address (str) – can be one of the case-insensitive names 'system', 'session' , or 'starter' or a valid D-Bus server address

property bus_type

Return the bus type: 'system', 'session' , or None.

dcar.auth

Authentication to a message bus.

Supported mechanisms:

  • EXTERNAL

  • DBUS_COOKIE_SHA1

  • ANONYMOUS

See: Authentication Protocol

dcar.auth.authenticate(sock, unix_fds)[source]

Authenticate to a message bus.

The passing of unix file descriptors will only be negotiated if unix_fds is True.

Parameters
  • sock (socket) – a connected socket

  • unix_fds (bool) – if the current Transport supports the passing of unix file descriptors this must be True

Returns

the GUID of the server and a bool that indicates whether unix file descriptor passing is possible (True) or not (False)

Return type

str, bool

Raises

AuthenticationError – if authentication failed

dcar.introspection

Introspection module.

New in version 0.3.0.

class dcar.introspection.Data(bus, name, path, xml)[source]

Bases: object

Introspection data.

If not provided, an instance of this class gets the XML data by calling org.freedesktop.DBus.Introspectable.Introspect.

The XML data is parsed and a data structure is created with a mapping from the names of members of the interfaces to a list of objects of type Method, Signal, or Property.

Access to objects:
  • data['member name']

  • data['interface name', 'member name']

Parameters
  • bus (dcar.Bus) – a connected bus object

  • name (str) – bus name

  • path (str) – object path

  • xml (str) – introspection data (will be loaded from D-Bus if None)

Raises
property xml

Return XML data.

class dcar.introspection.Method(name, interface, in_signature, out_signature, no_reply)

Bases: tuple

Representation of an interface member of type method.

in_signature

Alias for field number 2

interface

Alias for field number 1

name

Alias for field number 0

no_reply

Alias for field number 4

out_signature

Alias for field number 3

class dcar.introspection.Property(name, interface, signature, read, write, changed_signal)

Bases: tuple

Representation of an interface member of type property.

changed_signal

Alias for field number 5

interface

Alias for field number 1

name

Alias for field number 0

read

Alias for field number 3

signature

Alias for field number 2

write

Alias for field number 4

class dcar.introspection.Signal(name, interface, signature)

Bases: tuple

Representation of an interface member of type signal.

interface

Alias for field number 1

name

Alias for field number 0

signature

Alias for field number 2

dcar.bus

Connection to message bus.

class dcar.bus.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.

Parameters

address (str or Address) – same as for Address or an Address object

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.

raise_on_error()[source]

Re-raises the error or does nothing.

connect()[source]

Connect to message bus.

Raises
disconnect()[source]

Disconnect the client.

block(timeout=None)[source]

Blocks until send-loop and recv-loop are finished or timeout is reached.

The send-loop and recv-loop threads are started when connecting to the D-Bus.

Parameters

timeout (float) – timeout value in seconds (None means 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
  • msg (Message) – the message

  • timeout (float) – None = no timeout, 0 = no reply expected and > 0 = timeout in seconds

Returns

return values of the message call if a reply is expected else None

Return type

tuple or None

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

tuple or None

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 MessageInfo object.

Note

The handler functions for incoming method calls and signals will be executed in a separate thread sequentially.

Parameters
  • rule (MatchRule) – the match rule

  • handler (callable) – handler function for the signal

  • unicast (bool) – if True this rule applies to a unicast signal and no AddMatch message will be sent to the message bus

  • timeout (float) – timeout in seconds

Returns

ID of the signal

Return type

int

Raises
unregister_signal(reg_id, timeout=25.0)[source]

Unregister a signal.

Parameters
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 Bus object and a MessageInfo object.

Note

The handler functions for incoming method calls and signals will be executed in a separate thread sequentially.

Parameters
  • object_path (str) – object path

  • interface (str) – interface name

  • method_name (str) – method name

  • signature (str) – D-Bus type signatures of the arguments

Returns

ID of the method

Return type

int

Raises

RegisterError – if the method could not be registered

unregister_method(meth_id)[source]

Unregister a method.

Parameters

meth_id (int) – ID returned by register_method()

dcar.const

Some constants from dbus source files.

dcar.const.MAJOR_PROTOCOL_VERSION = b'\x01'

Major protocol version

dcar.const.MIN_HEADER_SIZE = 16

Minimum header size

dcar.const.MAX_MESSAGE_LEN = 134217728

Maximum message length

dcar.const.MAX_ARRAY_LEN = 67108864

Maximum array length

dcar.const.MAX_NAME_LEN = 255

Maximum name length

dcar.const.MAX_SIGNATURE_LEN = 255

Maximum signature length

dcar.const.MAX_MATCH_RULE_LEN = 1024

Maximum match rule length

dcar.const.MAX_MATCH_RULE_ARG_NUM = 63

Maximum number of match rule arguments

dcar.const.MAX_NESTING_DEPTH = 32

Maximum nesting depth of arrays and structs

dcar.const.MAX_VARIANT_NESTING_DEPTH = 64

Maximum nesting depth of variants

dcar.const.MAX_MSG_UNIX_FDS = 33554432

Maximum number of unix file descriptors

dcar.const.LOCAL_PATH = '/org/freedesktop/DBus/Local'

Reserved local path

dcar.const.LOCAL_INTERFACE = 'org.freedesktop.DBus.Local'

Reserved local interface

dcar.const.DEFAULT_TIMEOUT_VALUE = 25.0

Default timeout when waiting for a reply

dcar.errors

Errors module.

exception dcar.errors.Error[source]

Bases: Exception

Base class.

exception dcar.errors.AddressError[source]

Bases: dcar.errors.Error

Raised for errors in server addresses.

exception dcar.errors.AuthenticationError[source]

Bases: dcar.errors.Error

Raised when authentication failed.

exception dcar.errors.TransportError[source]

Bases: dcar.errors.Error

Raised for transport related errors.

exception dcar.errors.ValidationError[source]

Bases: dcar.errors.Error

Raised when validation failed.

exception dcar.errors.RegisterError[source]

Bases: dcar.errors.Error

Raised when a signal or method could not be registered.

exception dcar.errors.MessageError[source]

Bases: dcar.errors.Error

Raised for errors in messages.

exception dcar.errors.DBusError[source]

Bases: dcar.errors.MessageError

Raised for errors from ERROR messages.

exception dcar.errors.SignatureError[source]

Bases: dcar.errors.MessageError

Raised for errors in signatures.

exception dcar.errors.TooLongError[source]

Bases: dcar.errors.MessageError

Raised when a message, an array, a name etc. is too long.

dcar.marshal

Marshal/unmarshal D-Bus Messages.

See:

Note

Instances of the type classes should be used through the types mapping which uses D-Bus type codes as keys.

dcar.marshal.types

Mapping of D-Bus type codes to type class instances

class dcar.marshal.Type(name)[source]

Bases: object

Base class.

Parameters

name (str) – type name

marshal(raw, data, signature=None)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature=None)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.Fixed(name, struct_code)[source]

Bases: dcar.marshal.Type

Class for fixed types.

Parameters
  • name (str) – type name

  • struct_code (str) – code from struct module

marshal(raw, data, signature=None)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature=None)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.Boolean[source]

Bases: dcar.marshal.Fixed

Class for booleans.

marshal(raw, data, signature=None)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature=None)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.UnixFd[source]

Bases: dcar.marshal.Fixed

Class for unix file descriptors.

marshal(raw, data, signature=None)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature=None)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.StringLike(name, len_type, validate_func)[source]

Bases: dcar.marshal.Type

Class for string like types.

Parameters
  • name (str) – type name

  • len_type (str) – D-Bus type code for the length field

  • validate_func – a validate_* function from the validate module or None

marshal(raw, data, signature=None)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature=None)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.Container(name, alignment)[source]

Bases: dcar.marshal.Type

Base class for container types.

Parameters
  • name (str) – type name

  • alignment (int) – the type’s alignment

class dcar.marshal.Variant[source]

Bases: dcar.marshal.Container

Class for a D-Bus Variant.

marshal(raw, data, signature=None)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature=None)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.Array[source]

Bases: dcar.marshal.Container

Class for a D-Bus Array.

marshal(raw, data, signature)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.Struct(name='STRUCT')[source]

Bases: dcar.marshal.Container

Class for a D-Bus Struct.

marshal(raw, data, signature)[source]

Marshal an object of this type.

The data must be of an appropriate type according to the column Python IN in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
  • raw (RawData) – raw message data

  • data – data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

unmarshal(raw, signature)[source]

Unmarshal an object of this type.

The returned data will be of a type according to the column Python OUT in the types summary.

The signature parameter is only used in the classes Array, Struct, and DictEntry.

Parameters
Returns

unmarshalled data

Raises

MessageError – if the data could not be unmarshalled

class dcar.marshal.DictEntry[source]

Bases: dcar.marshal.Struct

Class for a D-Bus DictEntry.

dcar.marshal.marshal(raw, data, signature)[source]

Marshal objects.

The elements of the data tuple must be of appropriate types according to the column Python IN in the types summary.

Parameters
  • raw (RawData) – raw message data

  • data (tuple) – tuple of data to be marshalled

  • signature – see Signature

Raises

MessageError – if the data could not be marshalled

dcar.marshal.unmarshal(raw, signature)[source]

Unmarshal objects.

The elements of the returned tuple will be of types according to the column Python OUT in the types summary.

Parameters
Returns

tuple of unmarshalled data

Return type

tuple

Raises

MessageError – if the data could not be unmarshalled

dcar.message

D-Bus Message.

See: Message Protocol

class dcar.message.Byteorder(value)[source]

Bases: dcar.message.EnumReprMixin, enum.Enum

Enumeration of byteorders.

LITTLE = b'l'
BIG = b'B'
NATIVE = b'l'
class dcar.message.MessageType(value)[source]

Bases: dcar.message.EnumReprMixin, enum.Enum

Enumeration of message types.

INVALID = b'\x00'
METHOD_CALL = b'\x01'
METHOD_RETURN = b'\x02'
ERROR = b'\x03'
SIGNAL = b'\x04'
class dcar.message.HeaderFlag(value)[source]

Bases: enum.IntFlag

Enumeration of header flags.

NONE = 0
NO_REPLY_EXPECTED = 1
NO_AUTO_START = 2
ALLOW_INTERACTIVE_AUTHORIZATION = 4
classmethod from_byte(byte)[source]

Convert byte to a header flag.

to_byte()[source]

Convert header flag to a byte.

class dcar.message.HeaderField(value)[source]

Bases: dcar.message.EnumReprMixin, enum.Enum

Enumeration of header fields.

PATH = 1
INTERFACE = 2
MEMBER = 3
ERROR_NAME = 4
REPLY_SERIAL = 5
DESTINATION = 6
SENDER = 7
SIGNATURE = 8
UNIX_FDS = 9
class dcar.message.HeaderFields[source]

Bases: object

Fields in a message header.

signature = 'a(yv)'
to_list()[source]

Convert the internal dict representation to a list.

classmethod from_list(lst)[source]

Convert a list to the internal dict representation.

check(message_type)[source]

Check if required header fields are present and validate them.

Parameters

message_type (MessageType) – the message type

Raises
class dcar.message.Message(message_type, flags, fields, body)[source]

Bases: object

A D-Bus message.

Objects of this type must be treated as immutable.

Parameters
Raises
property info

Return a MessageInfo object.

Only available for messages of type METHOD_CALL and SIGNAL.

property reply_expected

Return True if a reply is expected.

property reply_serial

Return the reply serial from the header fields.

property sender

Return the sender from the header fields.

raise_on_error()[source]

Raise a DBusError if this is an ERROR message.

classmethod from_bytes(raw)[source]

Create a new message object from bytes.

Parameters

raw (RawData) – raw message data

Raises

MessageError – if the message could not be created

to_bytes()[source]

Convert this message to bytes.

Raises

MessageError – if the message could not be converted

class dcar.message.MessageInfo(serial, args, path, interface, member, sender, no_reply_expected, allow_interactive_authorization, is_signal)

Bases: tuple

Objects of this type will be passed to handler functions registered with register_signal() and register_method().

allow_interactive_authorization

header flag

args

arguments as a tuple

interface

interface name

is_signal

True if signal

member

member (signal or method) name

no_reply_expected

header flag

path

object path

sender

name of the sender’s connection

serial

message serial

dcar.raw

Raw message data.

class dcar.raw.RawData(initial_bytes=b'')[source]

Bases: _io.BytesIO

Raw messge data.

property unix_fds

Return list with unix file descriptors.

write(b)[source]

Write bytes.

write_nul_bytes(n)[source]

Write n NUL bytes.

write_padding(alignment)[source]

Write padding bytes.

skip_padding(alignment)[source]

Skip padding bytes.

set_value(pos, fixed_type, value)[source]

Set value at position pos.

add_unix_fd(fd)[source]

Add unix file descriptor.

nesting_depth()[source]

Context manager for checking the nesting depth of variants.

dcar.remote

Remote module.

New in version 0.3.0.

class dcar.remote.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 MessageInfo object as its only argument: obj.SomeSignal = function. The handler can be removed by assigning None.

See also: Types summary

Parameters
  • bus (dcar.Bus) – a connected bus object

  • name (str) – bus name

  • path (str) – object path

  • xml (str) – introspection data (will be loaded from D-Bus if None)

Raises
property xml

Return XML data.

class dcar.remote.DBus(bus)[source]

Bases: dcar.remote.RemoteObject

Convenience subclass of RemoteObject.

Parameters:
  • name = ‘org.freedesktop.DBus’

  • path = ‘/org/freedesktop/DBus’

See: Section Message Bus Messages in the D-Bus specification.

class dcar.remote.Notifications(bus)[source]

Bases: dcar.remote.RemoteObject

Convenience subclass of RemoteObject.

Parameters:
  • name = ‘org.freedesktop.Notifications’

  • path = ‘/org/freedesktop/Notifications’

See: Desktop Notifications Specification and Kitsiso.

class dcar.remote.PowerManagement(bus)[source]

Bases: dcar.remote.RemoteObject

Convenience subclass of RemoteObject.

Parameters:
  • name = ‘org.freedesktop.PowerManagement’

  • path = ‘/org/freedesktop/PowerManagement’

class dcar.remote.Login1(bus)[source]

Bases: dcar.remote.RemoteObject

Convenience subclass of RemoteObject.

Parameters:
  • name = ‘org.freedesktop.login1’

  • path = ‘/org/freedesktop/login1’

See: Section The Manager Object in the logind documentation.

dcar.router

Message routing.

class dcar.router.Router(bus)[source]

Bases: object

Class for routing in- and outgoing messages.

outgoing(msg, timeout)[source]

Handle outgoing messages.

Parameters
  • msg (Message) – the message

  • timeout (float) – timeout in seconds

Returns

return values of a message call if a reply is expected or None

Return type

tuple or None

Raises
incoming(msg)[source]

Handle incoming messages.

Parameters

msg (Message) – the message

class dcar.router.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.

object_path: str = None
interface: str = None
signal_name: str = None
sender: str = None
path_namespace: str = None
destination: str = None
arg0namespace: str = None
args: dict
argpaths: dict
add_arg(idx, arg)[source]

Add an arg match at idx.

add_argpath(idx, argpath)[source]

Add an argpath match at idx.

class dcar.router.Registry[source]

Bases: object

Base class for registries.

add(item, handler, *args)[source]

Add an item.

Parameters
  • item – depends on type of registry subclass

  • handler (callable) – handler function

  • args – additional arguments

remove(item_id)[source]

Remove an item with ID item_id.

class dcar.router.Signals[source]

Bases: dcar.router.Registry

Signals registry.

An item for this type’s add() method is a MatchRule (see also: register_signal()).

params = ('msginfo',)

handler parameters

matches(msg, unique_name)[source]

Match a SIGNAL message to a rule.

This function is a generator which yields the handler function for each matching rule.

class dcar.router.Methods[source]

Bases: dcar.router.Registry

Methods registry.

An item for this type’s add() method is a tuple (object_path, interface, method_name) (see also: register_method()).

params = ('bus', 'msginfo')

handler parameters

find(msg)[source]

Return handler function and signature for a METHOD_CALL message.

dcar.signature

D-Bus type signature.

class dcar.signature.Signature(sig)[source]

Bases: object

A signature.

The signature string will be parsed into a list of complete types. Each complete type is a tuple with the fist element being its signature. The second element is None for all basic (i.e. fixed and string-like) types, an empty list for variants, and a list of complete types for arrays, structs, and dict entries.

A Signature object can be used as an iterator which yields tuples of complete types.

Parameters

sig (str) – D-Bus type signature

Raises

SignatureError – if there is a problem with the signature

dcar.transports

Transports for message bus connections.

class dcar.transports.Transport(params, router)[source]

Bases: object

Base class.

Parameters
  • params (dict) – address parameters

  • router (Router) – router object

property error

Return the error which caused disconnection or None.

connect()[source]

Connect to message bus.

disconnect()[source]

Disconnect from message bus.

authenticate()[source]

Authenticate to message bus.

start_loops()[source]

Start threads with recv-loop and send-loop.

block(timeout=None)[source]

Block until loop threads are finished.

Parameters

timeout (float) – timeout value in seconds (None means no timeout)

Changed in version 0.2.0: Add parameter timeout

class dcar.transports.UnixTransport(params, router)[source]

Bases: dcar.transports.Transport

Transport that uses a unix domain socket.

It supports the passing of file descriptors.

class dcar.transports.TcpTransport(params, router)[source]

Bases: dcar.transports.Transport

Transport that uses a TCP socket.

class dcar.transports.NonceTcpTransport(params, router)[source]

Bases: dcar.transports.TcpTransport

Transport that uses a nonce-authenticated TCP socket.

connect()[source]

Connect to message bus.

dcar.validate

Validation functions.

The is_valid_* functions return True if the argument is valid, otherwise False.

The validate_* functions raise a ValidationError if validation failed or else return the argument unchanged.

dcar.validate.is_valid_bus_name(s, unique=False, strict=True)[source]
dcar.validate.is_valid_error_name(s)[source]
dcar.validate.is_valid_interface_name(s)[source]
dcar.validate.is_valid_member_name(s)[source]
dcar.validate.is_valid_object_path(s)[source]
dcar.validate.is_valid_serial(i)[source]
dcar.validate.is_valid_signature(s)[source]
dcar.validate.is_valid_unixfds_field(i)[source]
dcar.validate.validate_bus_name(s, unique=False, strict=True)[source]
dcar.validate.validate_error_name(s)[source]
dcar.validate.validate_interface_name(s)[source]
dcar.validate.validate_member_name(s)[source]
dcar.validate.validate_object_path(s)[source]
dcar.validate.validate_serial(i)[source]
dcar.validate.validate_signature(s)[source]
dcar.validate.validate_unixfds_field(i)[source]