summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-03-14 17:18:46 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-03-14 17:18:46 +0100
commit326de0f16155dc8a5729bffe0057282c3232141b (patch)
treebfd474a5395c7e5b317ace20d12411ea74046c3c
parentae172f84ddb9ff9c2fc26dd5ee16c1edd38d08ba (diff)
downloadpoezio-326de0f16155dc8a5729bffe0057282c3232141b.tar.gz
poezio-326de0f16155dc8a5729bffe0057282c3232141b.tar.bz2
poezio-326de0f16155dc8a5729bffe0057282c3232141b.tar.xz
poezio-326de0f16155dc8a5729bffe0057282c3232141b.zip
Factorise the /version callback and make it handle errors
Fixes #3376.
-rw-r--r--poezio/core/commands.py22
-rw-r--r--poezio/core/handlers.py19
-rw-r--r--poezio/fixes.py17
-rw-r--r--poezio/tabs/conversationtab.py16
-rw-r--r--poezio/tabs/muctab.py15
-rw-r--r--poezio/tabs/privatetab.py16
6 files changed, 29 insertions, 76 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index a6d8bcbb..8c7cbcd2 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -16,7 +16,6 @@ from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath
from poezio import common
-from poezio import fixes
from poezio import pep
from poezio import tabs
from poezio.bookmarks import Bookmark
@@ -297,29 +296,16 @@ class CommandCore:
"""
/version <jid>
"""
-
- def callback(res):
- "Callback for /version"
- if not res:
- return self.core.information('Could not get the software'
- ' version from %s' % jid,
- 'Warning')
- version = '%s is running %s version %s on %s' % (
- jid, res.get('name') or 'an unknown software',
- res.get('version') or 'unknown',
- res.get('os') or 'an unknown platform')
- self.core.information(version, 'Info')
-
if args is None:
return self.help('version')
-
jid = safeJID(args[0])
if jid.resource or jid not in roster or not roster[jid].resources:
- fixes.get_version(self.core.xmpp, jid, callback=callback)
+ self.core.xmpp.plugin['xep_0092'].get_version(
+ jid, callback=self.core.handler.on_version_result)
elif jid in roster:
for resource in roster[jid].resources:
- fixes.get_version(
- self.core.xmpp, resource.jid, callback=callback)
+ self.core.xmpp.plugin['xep_0092'].get_version(
+ resource.jid, callback=self.core.handler.on_version_result)
def _empty_join(self):
tab = self.core.current_tab()
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index 60cf405d..8c799b58 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -913,6 +913,25 @@ class HandlerCore:
_composing_tab_state(tab, state)
self.core.refresh_tab_win()
+ def on_version_result(self, iq):
+ """
+ Handle the result of a /version command.
+ """
+ jid = iq['from']
+ if iq['type'] == 'error':
+ error_condition = iq['error']['condition']
+ error_text = iq['error']['text']
+ reply = '%s: %s' % (error_condition, error_text) if error_text else error_condition
+ return self.core.information('Could not get the software '
+ 'version from %s: %s' % (jid, reply),
+ 'Warning')
+ res = iq['software_version']
+ version = '%s is running %s version %s on %s' % (
+ jid, res.get('name', 'an unknown software'),
+ res.get('version', 'unknown'),
+ res.get('os', 'an unknown platform'))
+ self.core.information(version, 'Info')
+
### subscription-related handlers ###
def on_roster_update(self, iq):
diff --git a/poezio/fixes.py b/poezio/fixes.py
index 77688bf8..f8de7b14 100644
--- a/poezio/fixes.py
+++ b/poezio/fixes.py
@@ -25,23 +25,6 @@ def has_identity(xmpp, jid, identity, on_true=None, on_false=None):
xmpp.plugin['xep_0030'].get_info(jid=jid, callback=_cb)
-def get_version(xmpp, jid, callback=None, **kwargs):
- def handle_result(res):
- if res and res['type'] != 'error':
- ret = res['software_version'].values
- else:
- ret = False
- if callback:
- callback(ret)
- return ret
-
- iq = xmpp.make_iq_get(ito=jid)
- iq['query'] = 'jabber:iq:version'
- result = iq.send(callback=handle_result if callback else None)
- if not callback:
- return handle_result(result)
-
-
def get_room_form(xmpp, room, callback):
def _cb(result):
if result["type"] == "error":
diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py
index 8b713b2d..a8a22b4a 100644
--- a/poezio/tabs/conversationtab.py
+++ b/poezio/tabs/conversationtab.py
@@ -19,7 +19,6 @@ import curses
from poezio.tabs.basetabs import OneToOneTab, Tab
from poezio import common
-from poezio import fixes
from poezio import windows
from poezio import xhtml
from poezio.common import safeJID
@@ -240,18 +239,6 @@ class ConversationTab(OneToOneTab):
"""
/version [jid]
"""
-
- def callback(res):
- if not res:
- return self.core.information(
- 'Could not get the software version from %s' % (jid, ),
- 'Warning')
- version = '%s is running %s version %s on %s' % (
- jid, res.get('name') or 'an unknown software',
- res.get('version') or 'unknown',
- res.get('os') or 'an unknown platform')
- self.core.information(version, 'Info')
-
if args:
return self.core.command.version(args[0])
jid = safeJID(self.name)
@@ -259,7 +246,8 @@ class ConversationTab(OneToOneTab):
if jid in roster:
resource = roster[jid].get_highest_priority_resource()
jid = resource.jid if resource else jid
- fixes.get_version(self.core.xmpp, jid, callback=callback)
+ self.core.xmpp.plugin['xep_0092'].get_version(
+ jid, callback=self.core.handler.on_version_result)
@command_args_parser.ignored
def command_add(self):
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index afe62188..59ef9054 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -1340,18 +1340,6 @@ class MucTab(ChatTab):
"""
/version <jid or nick>
"""
-
- def callback(res):
- if not res:
- return self.core.information('Could not get the software '
- 'version from %s' % (jid, ),
- 'Warning')
- version = '%s is running %s version %s on %s' % (
- jid, res.get('name') or 'an unknown software',
- res.get('version') or 'unknown',
- res.get('os') or 'an unknown platform')
- self.core.information(version, 'Info')
-
if args is None:
return self.core.command.help('version')
nick = args[0]
@@ -1360,7 +1348,8 @@ class MucTab(ChatTab):
jid = safeJID(jid + '/' + nick)
else:
jid = safeJID(nick)
- fixes.get_version(self.core.xmpp, jid, callback=callback)
+ self.core.xmpp.plugin['xep_0092'].get_version(
+ jid, callback=self.core.handler.on_version_result)
@command_args_parser.quoted(1)
def command_nick(self, args):
diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py
index 96c68562..d0a12232 100644
--- a/poezio/tabs/privatetab.py
+++ b/poezio/tabs/privatetab.py
@@ -17,7 +17,6 @@ import curses
from poezio.tabs import OneToOneTab, MucTab, Tab
-from poezio import fixes
from poezio import windows
from poezio import xhtml
from poezio.common import safeJID
@@ -207,22 +206,11 @@ class PrivateTab(OneToOneTab):
"""
/version
"""
-
- def callback(res):
- if not res:
- return self.core.information(
- 'Could not get the software version from %s' % (jid, ),
- 'Warning')
- version = '%s is running %s version %s on %s' % (
- jid, res.get('name') or 'an unknown software',
- res.get('version') or 'unknown',
- res.get('os') or 'an unknown platform')
- self.core.information(version, 'Info')
-
if args:
return self.core.command.version(args[0])
jid = safeJID(self.name)
- fixes.get_version(self.core.xmpp, jid, callback=callback)
+ self.core.xmpp.plugin['xep_0092'].get_version(
+ jid, callback=self.core.handler.on_version_result)
@command_args_parser.quoted(0, 1)
def command_info(self, arg):