# HG changeset patch # User Goffi # Date 1396261393 -7200 # Node ID 91836a647515f4eb60c780a2fd08dd19b7b52e96 # Parent 027a054c6dda6fe836c68133f6eff8a806bd2a5d plugin XEP-0092: use of checkFeature instead of hasFeature + timeout + message adapted to failure if software version is not available diff -r 027a054c6dda -r 91836a647515 src/plugins/plugin_xep_0092.py --- 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)