dbus/test/python test-client.py,1.8,1.9 test-service.py,1.4,1.5

Robert McQueen robot101 at freedesktop.org
Sat Oct 29 15:41:09 PDT 2005


Update of /cvs/dbus/dbus/test/python
In directory gabe:/tmp/cvs-serv15872/test/python

Modified Files:
	test-client.py test-service.py 
Log Message:
2005-10-29  Robert McQueen  <robot101 at debian.org>

        * python/service.py: Major changes to allow multiple inheritance
        from classes that define D-Bus interfaces:

         1. Create a new Interface class which is the parent class of
            Object, and make the ObjectType metaclass into InterfaceType.

         2. Patch written with Rob Taylor to replace use of method_vtable
            with code that walks the class's __MRO__ (method resolution order)
            to behave like Python does when invoking methods and allow
            overriding as you'd expect. Code is quite tricky because
            we have to find two methods, the one to invoke which has the
            right name and isn't decorated with the /wrong/ interface,
            and the one to pick up the signatures from which is decorated
            with the right interface.

            The same caveats apply as to normal multiple inheritance -
            this has undefined behaviour if you try and inherit from two
            classes that define a method with the same name but are
            decorated with different interfaces. You should decorate
            your overriding method with the interface you want.

         3. Replace grungy introspection XML generation code in the metaclass
            with dictionaries that cope correctly with multiple inheritance
            and the overriding of methods. This also uses the signature
            decorations to provide correct introspection data, including
            the debut appearance of the types of your return values. :D

        * test/python/test-client.py, test/python/test-service.py: Add a test
        case to try invoking an method that overrides one inherited from a
        D-Bus interface class.


Index: test-client.py
===================================================================
RCS file: /cvs/dbus/dbus/test/python/test-client.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- test-client.py	29 Oct 2005 19:13:17 -0000	1.8
+++ test-client.py	29 Oct 2005 22:41:07 -0000	1.9
@@ -144,6 +144,12 @@
                     self.assert_(ret in returns, "%s should return one of %s" % (method._method_name, repr(returns)))
         print
 
+    def testInheritance(self):
+        print "\n********* Testing inheritance from dbus.method.Interface ***********"
+        ret = self.iface.CheckInheritance()
+        print "CheckInheritance returned %s\n", str(ret)
+        self.assert_(ret, "overriding CheckInheritance from TestInterface failed")
+
 class TestDBusPythonToGLibBindings(unittest.TestCase):
     def setUp(self):
         self.bus = dbus.SessionBus()

Index: test-service.py
===================================================================
RCS file: /cvs/dbus/dbus/test/python/test-service.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- test-service.py	29 Oct 2005 19:13:17 -0000	1.4
+++ test-service.py	29 Oct 2005 22:41:07 -0000	1.5
@@ -18,7 +18,12 @@
 import gobject
 import random
 
-class TestObject(dbus.service.Object):
+class TestInterface(dbus.service.Interface):
+    @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='', out_signature='b')
+    def CheckInheritance(self):
+        return False
+
+class TestObject(dbus.service.Object, TestInterface):
     def __init__(self, bus_name, object_path="/org/freedesktop/DBus/TestSuitePythonObject"):
         dbus.service.Object.__init__(self, bus_name, object_path)
 
@@ -72,6 +77,9 @@
     def ReturnDict(self, test):
         return self.returnValue(test)
 
+    def CheckInheritance(self):
+        return True
+
 session_bus = dbus.SessionBus()
 name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
 object = TestObject(name)



More information about the dbus-commit mailing list