Mercurial > libervia-backend
changeset 952:91836a647515
plugin XEP-0092: use of checkFeature instead of hasFeature + timeout + message adapted to failure if software version is not available
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Mar 2014 12:23:13 +0200 |
parents | 027a054c6dda |
children | 4a577b170809 |
files | src/plugins/plugin_xep_0092.py |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0092.py Mon Mar 31 12:23:13 2014 +0200 +++ b/src/plugins/plugin_xep_0092.py Mon Mar 31 12:23:13 2014 +0200 @@ -19,11 +19,13 @@ from sat.core.i18n import _ from sat.core.constants import Const as C +from twisted.internet import reactor, defer from wokkel import compat from sat.core import exceptions from logging import debug, info, warning, error NS_VERSION = "jabber:iq:version" +TIMEOUT = 10 PLUGIN_INFO = { "name": "Software Version Plugin", @@ -58,17 +60,16 @@ - os: operating system of the queried entity """ client = self.host.getClient(profile_key) - def getVersion(available): - if not available: - raise exceptions.FeatureNotFound + def getVersion(dummy): iq_elt = compat.IQ(client.xmlstream, 'get') iq_elt['to'] = jid_.full() iq_elt.addElement("query", NS_VERSION) d = iq_elt.send() d.addCallback(self._gotVersion) return d - d = self.host.hasFeature(NS_VERSION, jid_, client.profile) + d = self.host.checkFeature(NS_VERSION, jid_, client.profile) d.addCallback(getVersion) + reactor.callLater(TIMEOUT, d.cancel) # XXX: timeout needed because some clients don't answer the IQ return d def _gotVersion(self, iq_elt): @@ -98,8 +99,11 @@ if os: whois_msg.append(_("Operating system: %s") % os) def versionEb(failure): - failure.trap(exceptions.FeatureNotFound) - whois_msg.append(_("Software informations not available")) + failure.trap(exceptions.FeatureNotFound, defer.CancelledError) + if failure.check(failure,exceptions.FeatureNotFound): + whois_msg.append(_("Software version not available")) + else: + whois_msg.append(_("Client software version request timeout")) d = self.getVersion(target_jid, profile) d.addCallbacks(versionCb, versionEb)