From 26cccef4d8e049613b4b815bf9b9bd5ac86dc087 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 30 Apr 2007 11:39:57 +0100 Subject: [PATCH] dbus/_bus_mixin.py: Add bindings for ListNames, ListActivatableNames, GetNameOwner too --- dbus/bus.py | 29 +++++++++++++++++++++++++++++ test/test-client.py | 24 ++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/dbus/bus.py b/dbus/bus.py index 070409e..6899b12 100644 --- a/dbus/bus.py +++ b/dbus/bus.py @@ -107,6 +107,35 @@ class _BusDaemonMixin(object): BUS_DAEMON_IFACE, 'ReleaseName', 's', (name,)) + def list_names(self): + """Return a list of all currently-owned names on the bus. + + :Returns: a dbus.Array of dbus.UTF8String + """ + return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, + BUS_DAEMON_IFACE, 'ListNames', + '', (), utf8_strings=True) + + def list_activatable_names(self): + """Return a list of all names that can be activated on the bus. + + :Returns: a dbus.Array of dbus.UTF8String + """ + return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, + BUS_DAEMON_IFACE, 'ListNames', + '', (), utf8_strings=True) + + def get_name_owner(self, bus_name): + """Return the unique connection name of the primary owner of the + given name. + + :Raises DBusException: if the `bus_name` has no owner + """ + validate_bus_name(bus_name, allow_unique=False) + return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, + BUS_DAEMON_IFACE, 'GetNameOwner', + 's', (bus_name,), utf8_strings=True) + def name_has_owner(self, bus_name): """Return True iff the given bus name has an owner on this bus. diff --git a/test/test-client.py b/test/test-client.py index 11be7db..b9d2242 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -60,11 +60,15 @@ test_types_vals = [1, 12323231, 3.14159265, 99999999.99, #([1,2,3],"c", 1.2, ["a","b","c"], {"a": (1,"v"), "b": (2,"d")}) ] +NAME = "org.freedesktop.DBus.TestSuitePythonService" +IFACE = "org.freedesktop.DBus.TestSuiteInterface" +OBJECT = "/org/freedesktop/DBus/TestSuitePythonObject" + class TestDBusBindings(unittest.TestCase): def setUp(self): self.bus = dbus.SessionBus() - self.remote_object = self.bus.get_object("org.freedesktop.DBus.TestSuitePythonService", "/org/freedesktop/DBus/TestSuitePythonObject") - self.iface = dbus.Interface(self.remote_object, "org.freedesktop.DBus.TestSuiteInterface") + self.remote_object = self.bus.get_object(NAME, OBJECT) + self.iface = dbus.Interface(self.remote_object, IFACE) def testWeakRefs(self): # regression test for Sugar crash caused by smcv getting weak refs @@ -307,6 +311,22 @@ class TestDBusBindings(unittest.TestCase): myself = self.iface.WhoAmI() print "I am", myself + def testBusGetNameOwner(self): + ret = self.bus.get_name_owner(NAME) + self.assert_(ret.startswith(':'), ret) + + def testBusListNames(self): + ret = self.bus.list_names() + self.assert_(NAME in ret, ret) + + def testBusListActivatableNames(self): + ret = self.bus.list_activatable_names() + self.assert_(NAME in ret, ret) + + def testBusNameHasOwner(self): + self.assert_(self.bus.name_has_owner(NAME)) + self.assert_(not self.bus.name_has_owner('badger.mushroom.snake')) + def testBusNameCreation(self): print '\n******** Testing BusName creation ********' test = [('org.freedesktop.DBus.Python.TestName', True), -- 2.11.4.GIT