[python] Multiple interfaces for one method / Register method with other name
simon.mcvittie at collabora.co.uk
Wed Nov 7 02:58:47 PST 2007
-----BEGIN PGP SIGNED MESSAGE-----
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.
def Foo(self, badgers, stoats):
def Foo(self, creatures):
my_foo = VersionedFoo(dbus.SessionBus(), '/com/example/Foo')
> # the first method: multiple decorators
> @dbus.service.method ("Interface1", ...)
> @dbus.service.method ("Interface2", ...)
> def foo1 (...):
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 (...):
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 (...):
> @dbus.service.method("Interface2", as_method="foo3", ...)
> def foo3_int2 (...):
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.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net
-----END PGP SIGNATURE-----
More information about the dbus