Created attachment 33757 [details] [review] Patch to fix _valid_interfaces attribute Before the status of the connection was set to CONNECTION_STATUS_CONNECTED (which calls self._get_interfaces()), the attribute _valid_interfaces (InterfaceFactory.) isn't the copy of self[CONN_INTERFACE].GetInterfaces(). Indeed, once Connection is created (but not connected), the attribute _valid_interfaces contains only set(['org.freedesktop.Telepathy.Connection', 'org.freedesktop.DBus.Properties']) In the other hand, self[CONN_INTERFACE].GetInterfaces() returns: dbus.Array([dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Aliasing'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Capabilities'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.SimplePresence'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Presence'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Avatars'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Contacts'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Requests'), dbus.String(u'org.laptop.Telepathy.Gadget'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.ContactCapabilities.DRAFT'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Location')], signature=dbus.Signature('s')) ---- So I created a patche which calls self[CONN_INTERFACE].GetInterfaces() and updates this attribute (_valid_interfaces) in the __init__ of Connection. Of course, you are free to modify this patch :) ---- HS: I had need this changes because I want to call SetPresence before calling Connect(), which wasn't possible before.
This is more of a documentation bug: the valid interfaces aren't necessarily known until the connection connects, so the result of GetInterfaces() is incomplete until CONNECTED is signalled. (Also, telepathy-python shouldn't block on D-Bus calls as your patch does.) The right thing to do is not trust _valid_interfaces to be complete until the Connection signals that it is "ready" (I believe there's a ready_handler __init__ argument or something?
Yep there is a ready handler, but it is emit when Connection is CONNECTED (which is good). So if I want to call SetPresence before calling Connect() (so before CONNECTED), I need a right _valid_interfaces attribute. Currently (before my patch), if we cant to change presence before calling Connect(), I get a KeyError because org.freedesktop.Telepathy.Connection.Interface.SimplePresence isn't in _valid_interfaces. I think we need an attribute which is always valid no?
The attribute can't always be valid (without blocking the main loop, which is bad - <http://smcv.pseudorandom.co.uk/2008/11/nonblocking/>), since on a newly created Connection we just don't have that information yet - we have to ask over D-Bus, which takes time. I think what you need to pre-load SimplePresence is something that resembles ready_handler, but can run as soon as the initial Status and Interfaces have been fetched, without waiting for CONNECTED. telepathy-qt4 has a mechanism like that, and putting a similar thing into telepathy-glib is among my medium-term plans for Telepathy. I'm not sure exactly how this should be implemented in telepathy-python, which doesn't natively have any mechanism for signals; perhaps binding telepathy-glib into Python would be a better long-term solution for this sort of thing. (In the meantime, if you know through out-of-band information, or your own call to GetInterfaces, that the Connection has the SimplePresence interface, I believe you should be able to just make a dbus.Interface for it, and call the method on that?)
Yes I could bypass this by creating a specific code for this case but I don't want to patch my code :) So I prefer use your bindings all time. Anyway, for moment, the current method (patch) is good for my case. I let you decide how to allow this in the future (for example, calling SetPresence on SimplePresence, before connecting the connection without throw an error).
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/telepathy/telepathy-python/issues/12.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.