plugin XEP-0092: use of checkFeature instead of hasFeature + timeout + message adapted to failure if software version is not available

This commit is contained in:
Goffi 2014-03-31 12:23:13 +02:00
commit c6884f14d5

View file

@ -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 @@ class XEP_0092(object):
- 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 @@ class XEP_0092(object):
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)