Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0092.py @ 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 | c6d8fc63b1db |
children | 91836a647515 |
comparison
equal
deleted
inserted
replaced
944:e1842ebcb2f3 | 945:899dc9cd0f35 |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from wokkel import disco, iwokkel, data_form, compat | 22 from wokkel import compat |
23 from sat.core import exceptions | 23 from sat.core import exceptions |
24 from logging import debug, info, warning, error | 24 from logging import debug, info, warning, error |
25 | 25 |
26 NS_VERSION = "jabber:iq:version" | 26 NS_VERSION = "jabber:iq:version" |
27 | 27 |
56 - name: Natural language name of the software | 56 - name: Natural language name of the software |
57 - version: specific version of the software | 57 - version: specific version of the software |
58 - os: operating system of the queried entity | 58 - os: operating system of the queried entity |
59 """ | 59 """ |
60 client = self.host.getClient(profile_key) | 60 client = self.host.getClient(profile_key) |
61 iq_elt = compat.IQ(client.xmlstream, 'get') | 61 def getVersion(available): |
62 iq_elt['to'] = jid_.full() | 62 if not available: |
63 query_elt = iq_elt.addElement("query", NS_VERSION) | 63 raise exceptions.FeatureNotFound |
64 d = iq_elt.send() | 64 iq_elt = compat.IQ(client.xmlstream, 'get') |
65 d.addCallback(self._gotVersion) | 65 iq_elt['to'] = jid_.full() |
66 iq_elt.addElement("query", NS_VERSION) | |
67 d = iq_elt.send() | |
68 d.addCallback(self._gotVersion) | |
69 return d | |
70 d = self.host.hasFeature(NS_VERSION, jid_, client.profile) | |
71 d.addCallback(getVersion) | |
66 return d | 72 return d |
67 | 73 |
68 def _gotVersion(self, iq_elt): | 74 def _gotVersion(self, iq_elt): |
69 try: | 75 try: |
70 query_elt = iq_elt.elements(NS_VERSION, 'query').next() | 76 query_elt = iq_elt.elements(NS_VERSION, 'query').next() |
90 if version: | 96 if version: |
91 whois_msg.append(_("Client version: %s") % version) | 97 whois_msg.append(_("Client version: %s") % version) |
92 if os: | 98 if os: |
93 whois_msg.append(_("Operating system: %s") % os) | 99 whois_msg.append(_("Operating system: %s") % os) |
94 def versionEb(failure): | 100 def versionEb(failure): |
95 whois_msg.append(_("Can't find software informations")) | 101 failure.trap(exceptions.FeatureNotFound) |
102 whois_msg.append(_("Software informations not available")) | |
96 | 103 |
97 d = self.getVersion(target_jid, profile) | 104 d = self.getVersion(target_jid, profile) |
98 d.addCallbacks(versionCb, versionEb) | 105 d.addCallbacks(versionCb, versionEb) |
99 return d | 106 return d |
100 | 107 |