python-dbus + static methods

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Jan 15 05:56:51 PST 2008


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

On Tue, 15 Jan 2008 at 14:14:27 +0100, Daniel Tabas wrote:
> dbus.exceptions.DBusException: org.freedesktop.DBus.Python.AttributeError:
> Traceback (most recent call last):
>   File "/var/lib/python-support/python2.5/dbus/service.py", line 625, in
> _message_cb
>     (candidate_method, parent_method) = _method_lookup(self, method_name,
> interface_name)
>   File "/var/lib/python-support/python2.5/dbus/service.py", line 188, in
> _method_lookup
>     if ("_dbus_is_method" in cls.__dict__[method_name].__dict__
> AttributeError: 'classmethod' object has no attribute '__dict__'

You can't apply the @method and @signal decorators to class or
static methods (this will continue to be the case unless dbus.service is
rewritten completely). Rename the class method, and export an instance method
that calls it:

    class MyObject(dbus.service.Object):
        ...
        @classmethod
        def do_things(cls, foo):
            return u'doing things to %r with %s' % (cls, foo)

        @dbus.service.method(MY_IFACE, in_signature='s', out_signature='s')
        def DoThings(self, foo):
            return self.do_things(foo)

or (more efficiently) just don't use a class method at all, in which
case you can use self.__class__ instead of cls if you need the object's
class for some reason:

    class MyObject(dbus.service.Object):
        ...
        @dbus.service.method(MY_IFACE, in_signature='s', out_signature='s')
        def DoThings(self, foo):
            return u'doing things to %r with %s' % (self.__class__, foo)

Regards,
    Simon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHjLujWSc8zVUw7HYRAikYAJ42Qp6QQlkmLgxFmkNC1RtkbzwE5gCeN0GO
P94j8mPGMF3EeRcouAPC3u0=
=jAkB
-----END PGP SIGNATURE-----


More information about the dbus mailing list