[python] Multiple interfaces for one method / Register method with other name

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Nov 7 02:58:47 PST 2007


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

On Tue, 06 Nov 2007 at 22:46:40 +0100, René 'Necoro' Neumann wrote:
> I have a question concerning the python-dbus bindings:
> Say I have a class A (=> a dbus-object A) which has several methods. And
> for some reasons (here: allow API versioning) I want that each method is
> defined in different interfaces.
> How could I do this?

Create a class with the interface 1 version of Foo(). Subclass it, and
give the subclass the interface 2 version of Foo(). Instantiate the subclass.

Like so:

    class _VersionedFoo_V1(dbus.service.Object):
        @dbus.service.method('com.example.Foo1',
                             in_signature='ss',
                             out_signature='')
        def Foo(self, badgers, stoats):
            pass

    class VersionedFoo(_VersionedFoo_V1):
        @dbus.service.method('com.example.Foo2',
                             in_signature='a{ss}',
                             out_signature='')
        def Foo(self, creatures):
            pass

    my_foo = VersionedFoo(dbus.SessionBus(), '/com/example/Foo')

> 	# the first method: multiple decorators
> 	@dbus.service.method ("Interface1", ...)
> 	@dbus.service.method ("Interface2", ...)
> 	def foo1 (...):
> 		pass

Doesn't and can't work, as currently implemented - the @method decorator
attaches metadata to the function object, so the first decorator (which
is actually run second) would overwrite the metadata from the second.

> 	# the second method: multiple interfaces in one decorator - as list
> 	@dbus.service.method (["Interface1", "Interface2"], ...)
> 	def foo2 (...):
> 		pass

I don't much like this interface, but it's a possibility.

> 	# the third way: register a function under a different name
> 	# this would also allow to have one function with different signatures
> in different interfaces
> 	@dbus.service.method("Interface1", ...)
> 	def foo3 (...):
> 		pass
> 
> 	@dbus.service.method("Interface2", as_method="foo3", ...)
> 	def foo3_int2 (...):
> 		pass

I wish this was possible, but the current implementation of method
dispatching makes it impossible. Please file a bug. However, the method
dispatching code will need rewriting to make this possible, so it's
unlikely to be fixed in the short term.

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

iD8DBQFHMZpnWSc8zVUw7HYRAsyFAJ0TeO7iTG8L0qFBgwNms3D11yMklQCfSYMF
nW2zgc5ecjstpITVuLhfbjM=
=D5jW
-----END PGP SIGNATURE-----


More information about the dbus mailing list