[PATCH][python] dbus.bus: detect NameHasNoOwner correctly, using new get_dbus_name() method

Simon McVittie simon.mcvittie at collabora.co.uk
Mon May 21 05:19:28 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- ---
 dbus/bus.py |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/dbus/bus.py b/dbus/bus.py
index 645f6a8..9313289 100644
- --- a/dbus/bus.py
+++ b/dbus/bus.py
@@ -42,6 +42,8 @@ _NAME_OWNER_CHANGE_MATCH = ("type='signal',sender='%s',"
 """(_NAME_OWNER_CHANGE_MATCH % sender) matches relevant NameOwnerChange
 messages"""
 
+_NAME_HAS_NO_OWNER = 'org.freedesktop.DBus.Error.NameHasNoOwner'
+
 _logger = logging.getLogger('dbus.bus')
 
 
@@ -55,8 +57,7 @@ class NameOwnerWatch(object):
             callback(new_owner)
 
         def error_cb(e):
- -            # FIXME: detect whether it's NameHasNoOwner properly
- -            if str(e).startswith('org.freedesktop.DBus.Error.NameHasNoOwner:'):
+            if e.get_dbus_name() == _NAME_HAS_NO_OWNER:
                 callback('')
             else:
                 logging.basicConfig()
@@ -158,10 +159,9 @@ class BusConnection(Connection):
             try:
                 return self.get_name_owner(bus_name)
             except DBusException, e:
- -                # FIXME: detect whether it's NameHasNoOwner, but properly
- -                #if not str(e).startswith('org.freedesktop.DBus.Error.NameHasNoOwner:'):
- -                #    raise
- -                # it might not exist: try to start it
+                if e.get_dbus_name() != _NAME_HAS_NO_OWNER:
+                    raise
+                # else it doesn't exist: try to start it
                 self.start_service_by_name(bus_name)
                 return self.get_name_owner(bus_name)
         else:
- -- 
1.5.2-rc3.GIT

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net

iD8DBQFGUY5QWSc8zVUw7HYRAkOzAJ9GeFYXMSpFgPpJtnelHV+QuIOSlwCcD9gV
bzHTdUSprBG2BLSxPKObYiA=
=rUbz
-----END PGP SIGNATURE-----


More information about the dbus mailing list