diff options
author | Lance Stout <lancestout@gmail.com> | 2011-01-08 22:38:13 -0500 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-01-08 22:38:13 -0500 |
commit | 2076d506b469b932fc330743f2e56e76f52a045b (patch) | |
tree | 36ba6d747c59a986b8613d6aa0c502b2653cd16e /sleekxmpp/plugins/xep_0092/version.py | |
parent | 68ce47c9055f3ef485fe6810797032e7a5d8c370 (diff) | |
download | slixmpp-2076d506b469b932fc330743f2e56e76f52a045b.tar.gz slixmpp-2076d506b469b932fc330743f2e56e76f52a045b.tar.bz2 slixmpp-2076d506b469b932fc330743f2e56e76f52a045b.tar.xz slixmpp-2076d506b469b932fc330743f2e56e76f52a045b.zip |
Update the XEP-0092 plugin to the new style.
Diffstat (limited to 'sleekxmpp/plugins/xep_0092/version.py')
-rw-r--r-- | sleekxmpp/plugins/xep_0092/version.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/xep_0092/version.py b/sleekxmpp/plugins/xep_0092/version.py new file mode 100644 index 00000000..f59f8819 --- /dev/null +++ b/sleekxmpp/plugins/xep_0092/version.py @@ -0,0 +1,88 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2010 Nathanael C. Fritz + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +import sleekxmpp +from sleekxmpp import Iq +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.matcher import StanzaPath +from sleekxmpp.plugins.base import base_plugin +from sleekxmpp.plugins.xep_0092 import Version + + +log = logging.getLogger(__name__) + + +class xep_0092(base_plugin): + + """ + XEP-0092: Software Version + """ + + def plugin_init(self): + """ + Start the XEP-0092 plugin. + """ + self.xep = "0092" + self.description = "Software Version" + self.stanza = sleekxmpp.plugins.xep_0092.stanza + + self.name = self.config.get('name', 'SleekXMPP') + self.version = self.config.get('version', '0.1-dev') + self.os = self.config.get('os', '') + + self.getVersion = self.get_version + + self.xmpp.register_handler( + Callback('Software Version', + StanzaPath('iq/software_version'), + self._handle_version)) + + register_stanza_plugin(Iq, Version) + + def post_init(self): + """ + Handle cross-plugin dependencies. + """ + base_plugin.post_init(self) + self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version') + + def _handle_version(self, iq): + """ + Respond to a software version query. + + Arguments: + iq -- The Iq stanza containing the software version query. + """ + iq.reply() + iq['software_version']['name'] = self.name + iq['software_version']['version'] = self.version + iq['software_version']['os'] = self.os + iq.send() + + def get_version(self, jid, ifrom=None): + """ + Retrieve the software version of a remote agent. + + Arguments: + jid -- The JID of the entity to query. + """ + iq = self.xmpp.Iq() + iq['to'] = jid + if ifrom: + iq['from'] = ifrom + iq['type'] = 'get' + iq['query'] = Version.namespace + + result = iq.send() + + if result and result['type'] != 'error': + return result['software_version']._get_stanza_values() + return False |