async def get_system_bus(self) -> MessageBus: if self._dbus is not None: return self._dbus async with self._dbus_connect_lock: try: try: bus = await MessageBus(bus_type=BusType.SYSTEM).connect() except AuthError: # Fallback to anonymous connection bus = await MessageBus(bus_type=BusType.SYSTEM, auth=AuthAnnonymous()).connect() except OSError as e: raise api.DBusNotAvailableException() from e self._dbus = bus return bus
def stub_fail_bus(self) -> None: self._stub_bus_connected.set_exception( api.DBusNotAvailableException("Stub connection failed") )