From 9d0ab378067cd59e12a1ba2671c353e4a8bce356 Mon Sep 17 00:00:00 2001 From: Robert McQueen Date: Thu, 3 Nov 2005 16:13:53 +0000 Subject: 2005-11-03 Robert McQueen * python/_dbus.py, python/proxies.py, python/service.py: Add __repr__ functions to dbus.Bus, dbus.service.BusName and dbus.service.Object, tweak others to be consistent. * test/python/test-client.py: Tweak output of testInheritance. --- ChangeLog | 8 ++++++++ python/_dbus.py | 16 +++++++++++++++- python/proxies.py | 2 +- python/service.py | 7 +++++++ test/python/test-client.py | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e629546f..07db9afe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-11-03 Robert McQueen + + * python/_dbus.py, python/proxies.py, python/service.py: Add __repr__ + functions to dbus.Bus, dbus.service.BusName and dbus.service.Object, + tweak others to be consistent. + + * test/python/test-client.py: Tweak output of testInheritance. + 2005-10-29 Robert McQueen * python/service.py: Major changes to allow multiple inheritance diff --git a/python/_dbus.py b/python/_dbus.py index 2e7e671b..bb4c0428 100644 --- a/python/_dbus.py +++ b/python/_dbus.py @@ -68,6 +68,7 @@ class Bus: START_REPLY_ALREADY_RUNNING = dbus_bindings.DBUS_START_REPLY_ALREADY_RUNNING def __init__(self, bus_type=TYPE_SESSION, use_default_mainloop=True, private=False): + self._bus_type = bus_type self._connection = dbus_bindings.bus_get(bus_type, private) self._connection.add_filter(self._signal_func) @@ -196,6 +197,19 @@ class Bus: def start_service_by_name(self, named_service): return dbus_bindings.bus_start_service_by_name(self._connection, named_service) + def __repr__(self): + if self._bus_type == self.TYPE_SESSION: + name = 'SESSION' + elif self._bus_type == self.TYPE_SYSTEM: + name = 'SYSTEM' + elif self._bus_type == self.TYPE_STARTER: + name = 'STARTER' + else: + assert False, 'Unable to represent unknown bus type.' + + return '' % (name, id(self)) + __str__ = __repr__ + class SystemBus(Bus): """The system-wide message bus """ @@ -246,6 +260,6 @@ class Interface: return ret def __repr__(self): - return ''%( + return ''%( self._obj, self._dbus_interface, id(self)) __str__ = __repr__ diff --git a/python/proxies.py b/python/proxies.py index f1f33941..d13b72b1 100644 --- a/python/proxies.py +++ b/python/proxies.py @@ -222,7 +222,7 @@ class ProxyObject: return ret def __repr__(self): - return ''%( + return ''%( self._bus, self._named_service, self._object_path , id(self)) __str__ = __repr__ diff --git a/python/service.py b/python/service.py index 3809ca59..de68b614 100644 --- a/python/service.py +++ b/python/service.py @@ -28,6 +28,10 @@ class BusName: """Get the name of this service""" return self._named_service + def __repr__(self): + return '' % (self._named_service, self._bus, id(self)) + __str__ = __repr__ + def _dispatch_dbus_method_call(self, argument_list, message): """Calls method_to_call using argument_list, but handles exceptions, etc, and generates a reply to the DBus Message message @@ -280,3 +284,6 @@ class Object(Interface): return reflection_data + def __repr__(self): + return '' % (self._object_path, self._name, id(self)) + __str__ = __repr__ diff --git a/test/python/test-client.py b/test/python/test-client.py index e84afcdf..cb753fb8 100755 --- a/test/python/test-client.py +++ b/test/python/test-client.py @@ -147,7 +147,7 @@ class TestDBusBindings(unittest.TestCase): def testInheritance(self): print "\n********* Testing inheritance from dbus.method.Interface ***********" ret = self.iface.CheckInheritance() - print "CheckInheritance returned %s\n", str(ret) + print "CheckInheritance returned %s" % ret self.assert_(ret, "overriding CheckInheritance from TestInterface failed") class TestDBusPythonToGLibBindings(unittest.TestCase): -- cgit