changeset 945:899dc9cd0f35

plugin XEP-0092: feature check before requesting version
author Goffi <goffi@goffi.org>
date Fri, 28 Mar 2014 18:19:29 +0100
parents e1842ebcb2f3
children fe181994246a
files src/plugins/plugin_xep_0092.py
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0092.py	Fri Mar 28 18:07:22 2014 +0100
+++ b/src/plugins/plugin_xep_0092.py	Fri Mar 28 18:19:29 2014 +0100
@@ -19,7 +19,7 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
-from wokkel import disco, iwokkel, data_form, compat
+from wokkel import compat
 from sat.core import exceptions
 from logging import debug, info, warning, error
 
@@ -58,11 +58,17 @@
                  - os: operating system of the queried entity
         """
         client = self.host.getClient(profile_key)
-        iq_elt = compat.IQ(client.xmlstream, 'get')
-        iq_elt['to'] = jid_.full()
-        query_elt = iq_elt.addElement("query", NS_VERSION)
-        d = iq_elt.send()
-        d.addCallback(self._gotVersion)
+        def getVersion(available):
+            if not available:
+                raise exceptions.FeatureNotFound
+            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.addCallback(getVersion)
         return d
 
     def _gotVersion(self, iq_elt):
@@ -92,7 +98,8 @@
             if os:
                 whois_msg.append(_("Operating system: %s") % os)
         def versionEb(failure):
-            whois_msg.append(_("Can't find software informations"))
+            failure.trap(exceptions.FeatureNotFound)
+            whois_msg.append(_("Software informations not available"))
 
         d = self.getVersion(target_jid, profile)
         d.addCallbacks(versionCb, versionEb)