def connect(reactor, busAddress='session'): """ Connects to the specified bus and returns a L{twisted.internet.defer.Deferred} to the fully-connected L{DBusClientConnection}. @param reactor: L{twisted.internet.interfaces.IReactor} implementor @param busAddress: 'session', 'system', or a valid bus address as defined by the DBus specification. If 'session' (the default) or 'system' is supplied, the contents of the DBUS_SESSION_BUS_ADDRESS or DBUS_SYSTEM_BUS_ADDRESS environment variables will be used for the bus address, respectively. If DBUS_SYSTEM_BUS_ADDRESS is not set, the well-known address unix:path=/var/run/dbus/system_bus_socket will be used. @type busAddress: C{string} @rtype: L{DBusClientConnection} @returns: Deferred to L{DBusClientConnection} """ from txdbus import endpoints f = DBusClientFactory() d = f.getConnection() eplist = endpoints.getDBusEndpoints(reactor, busAddress) eplist.reverse() def try_next_ep(err): if eplist: eplist.pop().connect(f).addErrback(try_next_ep) else: d.errback( ConnectError( string=( 'Failed to connect to any bus address. Last error: ' + err.getErrorMessage() ) ) ) if eplist: try_next_ep(None) else: d.errback( ConnectError( string=( 'Failed to connect to any bus address. No valid bus ' 'addresses found' ) ) ) return d
def gde(self, addr, client=True): return endpoints.getDBusEndpoints(reactor, addr, client)