summaryrefslogtreecommitdiff
path: root/src/tabs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tabs')
-rw-r--r--src/tabs/basetabs.py17
-rw-r--r--src/tabs/conversationtab.py29
-rw-r--r--src/tabs/muctab.py208
-rw-r--r--src/tabs/privatetab.py17
-rw-r--r--src/tabs/rostertab.py100
-rw-r--r--src/tabs/xmltab.py36
6 files changed, 242 insertions, 165 deletions
diff --git a/src/tabs/basetabs.py b/src/tabs/basetabs.py
index 0a55640c..9c74c239 100644
--- a/src/tabs/basetabs.py
+++ b/src/tabs/basetabs.py
@@ -35,7 +35,7 @@ from decorators import refresh_wrapper
from logger import logger
from text_buffer import TextBuffer
from theming import get_theme, dump_tuple
-
+from decorators import command_args_parser
# getters for tab colors (lambdas, so that they are dynamic)
STATE_COLORS = {
@@ -544,11 +544,12 @@ class ChatTab(Tab):
self.command_say(xhtml.convert_simple_to_full_colors(txt))
self.cancel_paused_delay()
- def command_xhtml(self, arg):
+ @command_args_parser.raw
+ def command_xhtml(self, xhtml):
""""
/xhtml <custom xhtml>
"""
- message = self.generate_xhtml_message(arg)
+ message = self.generate_xhtml_message(xhtml)
if message:
message.send()
@@ -573,7 +574,7 @@ class ChatTab(Tab):
return self.name
@refresh_wrapper.always
- def command_clear(self, args):
+ def command_clear(self, ignored):
"""
/clear
"""
@@ -637,6 +638,7 @@ class ChatTab(Tab):
self.core.remove_timed_event(self.timed_event_paused)
self.timed_event_paused = None
+ @command_args_parser.raw
def command_correct(self, line):
"""
/correct <fixed message>
@@ -672,6 +674,7 @@ class ChatTab(Tab):
if self.text_win.pos != 0:
self.state = 'scrolled'
+ @command_args_parser.raw
def command_say(self, line, correct=False):
pass
@@ -728,8 +731,9 @@ class OneToOneTab(ChatTab):
jid=self.get_dest_jid(), timeout=5,
callback=self.features_checked)
- def command_attention(self, message=''):
- "/attention [message]"
+ @command_args_parser.raw
+ def command_attention(self, message):
+ """/attention [message]"""
if message is not '':
self.command_say(message, attention=True)
else:
@@ -738,6 +742,7 @@ class OneToOneTab(ChatTab):
msg['attention'] = True
msg.send()
+ @command_args_parser.raw
def command_say(self, line, correct=False, attention=False):
pass
diff --git a/src/tabs/conversationtab.py b/src/tabs/conversationtab.py
index 52c503d7..2ab33bb9 100644
--- a/src/tabs/conversationtab.py
+++ b/src/tabs/conversationtab.py
@@ -29,6 +29,7 @@ from config import config
from decorators import refresh_wrapper
from roster import roster
from theming import get_theme, dump_tuple
+from decorators import command_args_parser
class ConversationTab(OneToOneTab):
"""
@@ -88,6 +89,7 @@ class ConversationTab(OneToOneTab):
def completion(self):
self.complete_commands(self.input)
+ @command_args_parser.raw
def command_say(self, line, attention=False, correct=False):
msg = self.core.xmpp.make_message(self.get_dest_jid())
msg['type'] = 'chat'
@@ -149,19 +151,21 @@ class ConversationTab(OneToOneTab):
self.text_win.refresh()
self.input.refresh()
- def command_xhtml(self, arg):
- message = self.generate_xhtml_message(arg)
+ @command_args_parser.raw
+ def command_xhtml(self, xhtml):
+ message = self.generate_xhtml_message(xhtml)
if message:
message.send()
self.core.add_message_to_text_buffer(self._text_buffer, message['body'], None, self.core.own_nick)
self.refresh()
- def command_last_activity(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_last_activity(self, args):
"""
/activity [jid]
"""
- if arg.strip():
- return self.core.command_last_activity(arg)
+ if args is not None:
+ return self.core.command_last_activity(arg[0])
def callback(iq):
if iq['type'] != 'result':
@@ -191,7 +195,8 @@ class ConversationTab(OneToOneTab):
self.core.xmpp.plugin['xep_0012'].get_last_activity(self.general_jid, callback=callback)
@refresh_wrapper.conditional
- def command_info(self, arg):
+ @command_args_parser.ignored
+ def command_info(self):
contact = roster[self.get_dest_jid()]
jid = safeJID(self.get_dest_jid())
if contact:
@@ -210,12 +215,14 @@ class ConversationTab(OneToOneTab):
self._text_buffer.add_message("\x19%(info_col)s}No information available\x19o" % {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)})
return True
- def command_unquery(self, arg):
+ @command_args_parser.ignored
+ def command_unquery(self):
self.core.close_tab()
- def command_version(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_version(self, args):
"""
- /version
+ /version [jid]
"""
def callback(res):
if not res:
@@ -225,8 +232,8 @@ class ConversationTab(OneToOneTab):
res.get('version') or _('unknown'),
res.get('os') or _('an unknown platform'))
self.core.information(version, 'Info')
- if arg:
- return self.core.command_version(arg)
+ if args:
+ return self.core.command_version(args[0])
jid = safeJID(self.name)
if not jid.resource:
if jid in roster:
diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py
index 547830cb..8ea73e5c 100644
--- a/src/tabs/muctab.py
+++ b/src/tabs/muctab.py
@@ -29,7 +29,7 @@ import windows
import xhtml
from common import safeJID
from config import config
-from decorators import refresh_wrapper
+from decorators import refresh_wrapper, command_args_parser
from logger import logger
from roster import roster
from theming import get_theme, dump_tuple
@@ -300,15 +300,12 @@ class MucTab(ChatTab):
return the_input.new_completion(possible_affiliations, 2, '',
quotify=True)
+ @command_args_parser.quoted(1, 1, [''])
def command_invite(self, args):
"""/invite <jid> [reason]"""
- args = common.shell_split(args)
- if len(args) == 1:
- jid, reason = args[0], ''
- elif len(args) == 2:
- jid, reason = args
- else:
+ if args is None:
return self.core.command_help('invite')
+ jid, reason = args
self.core.command_invite('%s %s "%s"' % (jid, self.name, reason))
def completion_invite(self, the_input):
@@ -327,15 +324,17 @@ class MucTab(ChatTab):
self.user_win.refresh(self.users)
self.input.refresh()
- def command_info(self, arg):
+ @command_args_parser.quoted(1)
+ def command_info(self, args):
"""
/info <nick>
"""
- if not arg:
+ if args is None:
return self.core.command_help('info')
- user = self.get_user_by_name(arg)
+ nick = args[0]
+ user = self.get_user_by_name(nick)
if not user:
- return self.core.information(_("Unknown user: %s") % arg)
+ return self.core.information(_("Unknown user: %s") % nick)
theme = get_theme()
if user.jid:
user_jid = ' (\x19%s}%s\x19o)' % (
@@ -346,7 +345,7 @@ class MucTab(ChatTab):
info = _('\x19%s}%s\x19o%s: show: \x19%s}%s\x19o, affiliation:'
' \x19%s}%s\x19o, role: \x19%s}%s\x19o%s') % (
dump_tuple(user.color),
- arg,
+ nick,
user_jid,
dump_tuple(theme.color_show(user.show)),
user.show or 'Available',
@@ -358,7 +357,8 @@ class MucTab(ChatTab):
self.add_message(info, typ=0)
self.core.refresh_window()
- def command_configure(self, arg):
+ @command_args_parser.quoted(0)
+ def command_configure(self, ignored):
"""
/configure
"""
@@ -386,20 +386,21 @@ class MucTab(ChatTab):
muc.configure_room(self.core.xmpp, self.name, form)
self.core.close_tab()
- def command_cycle(self, arg):
+ @command_args_parser.raw
+ def command_cycle(self, msg):
"""/cycle [reason]"""
- self.command_part(arg)
+ self.command_part(args)
self.disconnect()
self.user_win.pos = 0
self.core.disable_private_tabs(self.name)
self.core.command_join('"/%s"' % self.own_nick)
- def command_recolor(self, arg):
+ @command_args_parser.quoted(0, 1, [''])
+ def command_recolor(self, args):
"""
/recolor [random]
Re-assign color to the participants of the room
"""
- arg = arg.strip()
compare_users = lambda x: x.last_talked
users = list(self.users)
sorted_users = sorted(users, key=compare_users, reverse=True)
@@ -409,7 +410,7 @@ class MucTab(ChatTab):
sorted_users.remove(user)
user.color = get_theme().COLOR_OWN_NICK
colors = list(get_theme().LIST_COLOR_NICKNAMES)
- if arg and arg == 'random':
+ if args[0] == 'random':
random.shuffle(colors)
for i, user in enumerate(sorted_users):
user.color = colors[i % len(colors)]
@@ -418,7 +419,8 @@ class MucTab(ChatTab):
self.text_win.refresh()
self.input.refresh()
- def command_version(self, arg):
+ @command_args_parser.quoted(1)
+ def command_version(self, args):
"""
/version <jid or nick>
"""
@@ -433,23 +435,25 @@ class MucTab(ChatTab):
res.get('version') or _('unknown'),
res.get('os') or _('an unknown platform'))
self.core.information(version, 'Info')
- if not arg:
+ if args is None:
return self.core.command_help('version')
- if arg in [user.nick for user in self.users]:
+ nick = args[0]
+ if nick in [user.nick for user in self.users]:
jid = safeJID(self.name).bare
- jid = safeJID(jid + '/' + arg)
+ jid = safeJID(jid + '/' + nick)
else:
- jid = safeJID(arg)
+ jid = safeJID(nick)
fixes.get_version(self.core.xmpp, jid,
- callback=callback)
+ callback=callback)
- def command_nick(self, arg):
+ @command_args_parser.quoted(1)
+ def command_nick(self, args):
"""
/nick <nickname>
"""
- if not arg:
+ if args is None:
return self.core.command_help('nick')
- nick = arg
+ nick = args[0]
if not self.joined:
return self.core.information(_('/nick only works in joined rooms'),
_('Info'))
@@ -460,11 +464,12 @@ class MucTab(ChatTab):
current_status.message,
current_status.show)
- def command_part(self, arg):
+ @command_args_parser.quoted(0, 1, [''])
+ def command_part(self, args):
"""
/part [msg]
"""
- arg = arg.strip()
+ arg = args[0]
msg = None
if self.joined:
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
@@ -505,37 +510,39 @@ class MucTab(ChatTab):
self.refresh()
self.core.doupdate()
- def command_close(self, arg):
+ @command_args_parser.raw
+ def command_close(self, msg):
"""
/close [msg]
"""
- self.command_part(arg)
+ self.command_part(args)
self.core.close_tab()
- def command_query(self, arg):
+ @command_args_parser.quoted(1, 1)
+ def command_query(self, args):
"""
/query <nick> [message]
"""
- args = common.shell_split(arg)
- if len(args) < 1:
- return
+ if args is None:
+ return self.core.command_help('query')
nick = args[0]
r = None
for user in self.users:
if user.nick == nick:
r = self.core.open_private_window(self.name, user.nick)
- if r and len(args) > 1:
+ if r and len(args) == 2:
msg = args[1]
self.core.current_tab().command_say(
xhtml.convert_simple_to_full_colors(msg))
if not r:
self.core.information(_("Cannot find user: %s" % nick), 'Error')
- def command_topic(self, arg):
+ @command_args_parser.raw
+ def command_topic(self, subject):
"""
/topic [new topic]
"""
- if not arg.strip():
+ if not subject:
self._text_buffer.add_message(
_("\x19%s}The subject of the room is: %s %s") %
(dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
@@ -544,10 +551,11 @@ class MucTab(ChatTab):
else ''))
self.refresh()
return
- subject = arg
+
muc.change_subject(self.core.xmpp, self.name, subject)
- def command_names(self, arg=None):
+ @command_args_parser.quoted(0)
+ def command_names(self, args):
"""
/names
"""
@@ -618,29 +626,28 @@ class MucTab(ChatTab):
return the_input.new_completion(word_list, 1, quotify=True)
- def command_kick(self, arg):
+ @command_args_parser.quoted(1, 1)
+ def command_kick(self, args):
"""
/kick <nick> [reason]
"""
- args = common.shell_split(arg)
- if not args:
- self.core.command_help('kick')
+ if args is None:
+ return self.core.command_help('kick')
+ if len(args) == 2:
+ msg = ' "%s"' % args[1]
else:
- if len(args) > 1:
- msg = ' "%s"' % args[1]
- else:
- msg = ''
- self.command_role('"'+args[0]+ '" none'+msg)
+ msg = ''
+ self.command_role('"'+args[0]+ '" none'+msg)
- def command_ban(self, arg):
+ @command_args_parser.quoted(1, 1)
+ def command_ban(self, args):
"""
/ban <nick> [reason]
"""
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.name)
- args = common.shell_split(arg)
- if not args:
+ if args is None:
return self.core.command_help('ban')
if len(args) > 1:
msg = args[1]
@@ -659,7 +666,8 @@ class MucTab(ChatTab):
if not res:
self.core.information('Could not ban user', 'Error')
- def command_role(self, arg):
+ @command_args_parser.quoted(2, 1, [''])
+ def command_role(self, args):
"""
/role <nick> <role> [reason]
Changes the role of an user
@@ -668,24 +676,25 @@ class MucTab(ChatTab):
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.name)
- args = common.shell_split(arg)
- if len(args) < 2:
- self.core.command_help('role')
- return
- nick, role = args[0], args[1]
- if len(args) > 2:
- reason = ' '.join(args[2:])
- else:
- reason = ''
- if not self.joined or \
- not role in ('none', 'visitor', 'participant', 'moderator'):
- return
+
+ if args is None:
+ return self.core.command_help('role')
+
+ nick, role, reason = args[0], args[1].lower(), args[2]
+
+ valid_roles = ('none', 'visitor', 'participant', 'moderator')
+
+ if not self.joined or role not in valid_roles:
+ return self.core.information(_('The role must be one of ' + ', '.join(valid_roles)),
+ _('Error'))
+
if not safeJID(self.name + '/' + nick):
return self.core('Invalid nick', 'Info')
muc.set_user_role(self.core.xmpp, self.name, nick, reason, role,
callback=callback)
- def command_affiliation(self, arg):
+ @command_args_parser.quoted(2)
+ def command_affiliation(self, args):
"""
/affiliation <nick> <role>
Changes the affiliation of an user
@@ -694,16 +703,20 @@ class MucTab(ChatTab):
def callback(iq):
if iq['type'] == 'error':
self.core.room_error(iq, self.name)
- args = common.shell_split(arg)
- if len(args) < 2:
- self.core.command_help('affiliation')
- return
+
+ if args is None:
+ return self.core.command_help('affiliation')
+
nick, affiliation = args[0], args[1].lower()
+
if not self.joined:
return
- if affiliation not in ('outcast', 'none', 'member', 'admin', 'owner'):
- self.core.command_help('affiliation')
- return
+
+ valid_affiliations = ('outcast', 'none', 'member', 'admin', 'owner')
+ if affiliation not in valid_affiliations:
+ return self.core.information(_('The affiliation must be one of ' + ', '.join(valid_affiliations)),
+ _('Error'))
+
if nick in [user.nick for user in self.users]:
res = muc.set_user_affiliation(self.core.xmpp, self.name,
affiliation, nick=nick,
@@ -715,6 +728,7 @@ class MucTab(ChatTab):
if not res:
self.core.information(_('Could not set affiliation'), _('Error'))
+ @command_args_parser.raw
def command_say(self, line, correct=False):
"""
/say <message>
@@ -753,20 +767,22 @@ class MucTab(ChatTab):
msg.send()
self.chat_state = needed
- def command_xhtml(self, arg):
- message = self.generate_xhtml_message(arg)
+ @command_args_parser.raw
+ def command_xhtml(self, msg):
+ message = self.generate_xhtml_message(msg)
if message:
message['type'] = 'groupchat'
message.send()
- def command_ignore(self, arg):
+ @command_args_parser.quoted(1)
+ def command_ignore(self, args):
"""
/ignore <nick>
"""
- if not arg:
- self.core.command_help('ignore')
- return
- nick = arg
+ if arg is None:
+ return self.core.command_help('ignore')
+
+ nick = args[0]
user = self.get_user_by_name(nick)
if not user:
self.core.information(_('%s is not in the room') % nick)
@@ -776,14 +792,15 @@ class MucTab(ChatTab):
self.ignores.append(user)
self.core.information(_("%s is now ignored") % nick, 'info')
- def command_unignore(self, arg):
+ @command_args_parser.quoted(1)
+ def command_unignore(self, args):
"""
/unignore <nick>
"""
- if not arg:
- self.core.command_help('unignore')
- return
- nick = arg
+ if arg is None:
+ return self.core.command_help('unignore')
+
+ nick = args[0]
user = self.get_user_by_name(nick)
if not user:
self.core.information(_('%s is not in the room') % nick)
@@ -1552,4 +1569,23 @@ class MucTab(ChatTab):
def matching_names(self):
return [(1, safeJID(self.name).user), (3, self.name)]
-
+ def enable_self_ping_event(self):
+ delay = config.get_by_tabname("self_ping_delay", self.general_jid, default=60)
+ if delay <= 0: # use 0 or some negative value to disable it
+ return
+ self.self_ping_event = timed_events.DelayedEvent(delay, self.send_self_ping)
+ self.core.add_timed_event(self.self_ping_event)
+
+ def send_self_ping(self):
+ to = self.name + "/" + self.own_nick
+ self.core.xmpp.plugin['xep_0199'].send_ping(jid=to,
+ callback=self.on_self_ping_result,
+ timeout_callback=self.on_self_ping_failed,
+ timeout=10)
+
+ def on_self_ping_result(self, iq):
+ if iq["type"] == "error":
+ self.command_part(iq["error"]["text"] or "not in this room")
+ self.core.refresh_window()
+ else: # Re-send a self-ping in a few seconds
+ self.enable_self_ping_event()
diff --git a/src/tabs/privatetab.py b/src/tabs/privatetab.py
index 4c01cd70..aa19d4d4 100644
--- a/src/tabs/privatetab.py
+++ b/src/tabs/privatetab.py
@@ -27,6 +27,7 @@ from config import config
from decorators import refresh_wrapper
from logger import logger
from theming import get_theme, dump_tuple
+from decorators import command_args_parser
class PrivateTab(OneToOneTab):
"""
@@ -120,6 +121,7 @@ class PrivateTab(OneToOneTab):
empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//'))
self.send_composing_chat_state(empty_after)
+ @command_args_parser.raw
def command_say(self, line, attention=False, correct=False):
if not self.on:
return
@@ -182,13 +184,15 @@ class PrivateTab(OneToOneTab):
self.text_win.refresh()
self.input.refresh()
- def command_unquery(self, arg):
+ @command_args_parser.ignored
+ def command_unquery(self):
"""
/unquery
"""
self.core.close_tab()
- def command_version(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_version(self, args):
"""
/version
"""
@@ -200,18 +204,19 @@ class PrivateTab(OneToOneTab):
res.get('version') or _('unknown'),
res.get('os') or _('an unknown platform'))
self.core.information(version, 'Info')
- if arg:
- return self.core.command_version(arg)
+ if args:
+ return self.core.command_version(args[0])
jid = safeJID(self.name)
fixes.get_version(self.core.xmpp, jid,
callback=callback)
+ @command_args_parser.quoted(0, 1)
def command_info(self, arg):
"""
/info
"""
- if arg:
- self.parent_muc.command_info(arg)
+ if args:
+ self.parent_muc.command_info(args[0])
else:
user = safeJID(self.name).resource
self.parent_muc.command_info(user)
diff --git a/src/tabs/rostertab.py b/src/tabs/rostertab.py
index 878e89ed..2e588b72 100644
--- a/src/tabs/rostertab.py
+++ b/src/tabs/rostertab.py
@@ -25,6 +25,7 @@ from contact import Contact, Resource
from decorators import refresh_wrapper
from roster import RosterGroup, roster
from theming import get_theme, dump_tuple
+from decorators import command_args_parser
class RosterInfoTab(Tab):
"""
@@ -158,7 +159,8 @@ class RosterInfoTab(Tab):
}
tab.add_message(message)
- def command_block(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_block(self, args):
"""
/block [jid]
"""
@@ -169,8 +171,8 @@ class RosterInfoTab(Tab):
return self.core.information('Contact blocked.', 'Info')
item = self.roster_win.selected_row
- if arg:
- jid = safeJID(arg)
+ if args:
+ jid = safeJID(args[0])
elif isinstance(item, Contact):
jid = item.bare_jid
elif isinstance(item, Resource):
@@ -185,7 +187,8 @@ class RosterInfoTab(Tab):
jids = roster.jids()
return the_input.new_completion(jids, 1, '', quotify=False)
- def command_unblock(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_unblock(self, args):
"""
/unblock [jid]
"""
@@ -196,8 +199,8 @@ class RosterInfoTab(Tab):
return self.core.information('Contact unblocked.', 'Info')
item = self.roster_win.selected_row
- if arg:
- jid = safeJID(arg)
+ if args:
+ jid = safeJID(args[0])
elif isinstance(item, Contact):
jid = item.bare_jid
elif isinstance(item, Resource):
@@ -218,7 +221,8 @@ class RosterInfoTab(Tab):
self.core.xmpp.plugin['xep_0191'].get_blocked(callback=on_result)
return True
- def command_list_blocks(self, arg=None):
+ @command_args_parser.ignored
+ def command_list_blocks(self):
"""
/list_blocks
"""
@@ -236,7 +240,8 @@ class RosterInfoTab(Tab):
self.core.xmpp.plugin['xep_0191'].get_blocked(callback=callback)
- def command_reconnect(self, args=None):
+ @command_args_parser.ignored
+ def command_reconnect(self):
"""
/reconnect
"""
@@ -245,19 +250,21 @@ class RosterInfoTab(Tab):
else:
self.core.xmpp.connect()
- def command_disconnect(self, args=None):
+ @command_args_parser.ignored
+ def command_disconnect(self):
"""
/disconnect
"""
self.core.disconnect()
- def command_last_activity(self, arg=None):
+ @command_args_parser.quoted(0, 1)
+ def command_last_activity(self, args):
"""
/activity [jid]
"""
item = self.roster_win.selected_row
- if arg:
- jid = arg
+ if args:
+ jid = args[0]
elif isinstance(item, Contact):
jid = item.bare_jid
elif isinstance(item, Resource):
@@ -335,7 +342,8 @@ class RosterInfoTab(Tab):
return the_input.auto_completion(end_list, '')
- def command_clear(self, arg=''):
+ @command_args_parser.ignored
+ def command_clear(self):
"""
/clear
"""
@@ -344,7 +352,8 @@ class RosterInfoTab(Tab):
self.core.information_win.rebuild_everything(self.core.information_buffer)
self.refresh()
- def command_password(self, arg):
+ @command_args_parser.quoted(1)
+ def command_password(self, args):
"""
/password <password>
"""
@@ -352,19 +361,18 @@ class RosterInfoTab(Tab):
if iq['type'] == 'result':
self.core.information('Password updated', 'Account')
if config.get('password'):
- config.silent_set('password', arg)
+ config.silent_set('password', args[0])
else:
self.core.information('Unable to change the password', 'Account')
- self.core.xmpp.plugin['xep_0077'].change_password(arg, callback=callback)
+ self.core.xmpp.plugin['xep_0077'].change_password(args[0], callback=callback)
-
-
- def command_deny(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_deny(self, args):
"""
/deny [jid]
Denies a JID from our roster
"""
- if not arg:
+ if not args:
item = self.roster_win.selected_row
if isinstance(item, Contact):
jid = item.bare_jid
@@ -372,7 +380,7 @@ class RosterInfoTab(Tab):
self.core.information('No subscription to deny')
return
else:
- jid = safeJID(arg).bare
+ jid = safeJID(args[0]).bare
if not jid in [jid for jid in roster.jids()]:
self.core.information('No subscription to deny')
return
@@ -383,12 +391,13 @@ class RosterInfoTab(Tab):
self.core.information('Subscription to %s was revoked' % jid,
'Roster')
+ @command_args_parser.quoted(1)
def command_add(self, args):
"""
Add the specified JID to the roster, and set automatically
accept the reverse subscription
"""
- jid = safeJID(safeJID(args.strip()).bare)
+ jid = safeJID(safeJID(args[0]).bare)
if not jid:
self.core.information(_('No JID specified'), 'Error')
return
@@ -398,7 +407,8 @@ class RosterInfoTab(Tab):
roster.modified()
self.core.information('%s was added to the roster' % jid, 'Roster')
- def command_name(self, arg):
+ @command_args_parser.quoted(1)
+ def command_name(self, args):
"""
Set a name for the specified JID in your roster
"""
@@ -406,7 +416,6 @@ class RosterInfoTab(Tab):
if not iq:
self.core.information('The name could not be set.', 'Error')
log.debug('Error in /name:\n%s', iq)
- args = common.shell_split(arg)
if not args:
return self.core.command_help('name')
jid = safeJID(args[0]).bare
@@ -424,13 +433,13 @@ class RosterInfoTab(Tab):
self.core.xmpp.update_roster(jid, name=name, groups=groups,
subscription=subscription, callback=callback)
+ @command_args_parser.quoted(2)
def command_groupadd(self, args):
"""
Add the specified JID to the specified group
"""
- args = common.shell_split(args)
- if len(args) != 2:
- return
+ if args is None:
+ return self.core.command_help('groupadd')
jid = safeJID(args[0]).bare
group = args[1]
@@ -464,12 +473,12 @@ class RosterInfoTab(Tab):
self.core.xmpp.update_roster(jid, name=name, groups=new_groups,
subscription=subscription, callback=callback)
- def command_groupmove(self, arg):
+ @command_args_parser.quoted(3)
+ def command_groupmove(self, args):
"""
Remove the specified JID from the first specified group and add it to the second one
"""
- args = common.shell_split(arg)
- if len(args) != 3:
+ if args is None:
return self.core.command_help('groupmove')
jid = safeJID(args[0]).bare
group_from = args[1]
@@ -519,13 +528,14 @@ class RosterInfoTab(Tab):
self.core.xmpp.update_roster(jid, name=name, groups=new_groups,
subscription=subscription, callback=callback)
+ @command_args_parser.quoted(2)
def command_groupremove(self, args):
"""
Remove the specified JID from the specified group
"""
- args = common.shell_split(args)
- if len(args) != 2:
- return
+ if args is None:
+ return self.core.command_help('groupremove')
+
jid = safeJID(args[0]).bare
group = args[1]
@@ -559,13 +569,14 @@ class RosterInfoTab(Tab):
self.core.xmpp.update_roster(jid, name=name, groups=new_groups,
subscription=subscription, callback=callback)
+ @command_args_parser.quoted(0, 1)
def command_remove(self, args):
"""
Remove the specified JID from the roster. i.e.: unsubscribe
from its presence, and cancel its subscription to our.
"""
- if args.strip():
- jid = safeJID(args.strip()).bare
+ if args:
+ jid = safeJID(args[0]).bare
else:
item = self.roster_win.selected_row
if isinstance(item, Contact):
@@ -576,12 +587,12 @@ class RosterInfoTab(Tab):
roster.remove(jid)
del roster[jid]
- def command_import(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_import(self, args):
"""
Import the contacts
"""
- args = common.shell_split(arg)
- if len(args):
+ if args:
if args[0].startswith('/'):
filepath = args[0]
else:
@@ -603,12 +614,12 @@ class RosterInfoTab(Tab):
self.command_add(jid.lstrip('\n'))
self.core.information('Contacts imported from %s' % filepath, 'Info')
- def command_export(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_export(self, args):
"""
Export the contacts
"""
- args = common.shell_split(arg)
- if len(args):
+ if args:
if args[0].startswith('/'):
filepath = args[0]
else:
@@ -697,11 +708,12 @@ class RosterInfoTab(Tab):
if contact.pending_in)
return the_input.new_completion(jids, 1, '', quotify=False)
- def command_accept(self, arg):
+ @command_args_parser.quoted(0, 1)
+ def command_accept(self, args):
"""
Accept a JID from in roster. Authorize it AND subscribe to it
"""
- if not arg:
+ if not args:
item = self.roster_win.selected_row
if isinstance(item, Contact):
jid = item.bare_jid
@@ -709,7 +721,7 @@ class RosterInfoTab(Tab):
self.core.information('No subscription to accept')
return
else:
- jid = safeJID(arg).bare
+ jid = safeJID(args[0]).bare
nodepart = safeJID(jid).user
jid = safeJID(jid)
# crappy transports putting resources inside the node part
diff --git a/src/tabs/xmltab.py b/src/tabs/xmltab.py
index 083e97c5..84ecf00c 100644
--- a/src/tabs/xmltab.py
+++ b/src/tabs/xmltab.py
@@ -19,6 +19,7 @@ from . import Tab
import windows
from xhtml import clean_text
+from decorators import command_args_parser
class XMLTab(Tab):
def __init__(self):
@@ -70,46 +71,53 @@ class XMLTab(Tab):
self.text_win.toggle_lock()
self.refresh()
- def command_filter_xmlmask(self, arg):
+ @command_args_parser.raw
+ def command_filter_xmlmask(self, mask):
"""/filter_xmlmask <xml mask>"""
try:
- handler = Callback('custom matcher', matcher.MatchXMLMask(arg),
+ handler = Callback('custom matcher', matcher.MatchXMLMask(mask),
self.core.incoming_stanza)
self.core.xmpp.remove_handler('custom matcher')
self.core.xmpp.register_handler(handler)
self.filter_type = "XML Mask Filter"
- self.filter = arg
+ self.filter = mask
self.refresh()
except:
self.core.information('Invalid XML Mask', 'Error')
self.command_reset('')
- def command_filter_id(self, arg):
+ @command_args_parser.quoted(1)
+ def command_filter_id(self, args):
"""/filter_id <id>"""
+ if args is None:
+ return self.core.command_help('filter_id')
+
self.core.xmpp.remove_handler('custom matcher')
handler = Callback('custom matcher', matcher.MatcherId(arg),
self.core.incoming_stanza)
self.core.xmpp.register_handler(handler)
self.filter_type = "Id Filter"
- self.filter = arg
+ self.filter = args[0]
self.refresh()
- def command_filter_xpath(self, arg):
+ @command_args_parser.raw
+ def command_filter_xpath(self, xpath):
"""/filter_xpath <xpath>"""
try:
handler = Callback('custom matcher', matcher.MatchXPath(
- arg.replace('%n', self.core.xmpp.default_ns)),
+ xpath.replace('%n', self.core.xmpp.default_ns)),
self.core.incoming_stanza)
self.core.xmpp.remove_handler('custom matcher')
self.core.xmpp.register_handler(handler)
self.filter_type = "XPath Filter"
- self.filter = arg
+ self.filter = xpath
self.refresh()
except:
self.core.information('Invalid XML Path', 'Error')
self.command_reset('')
- def command_reset(self, arg):
+ @command_args_parser.ignored
+ def command_reset(self):
"""/reset"""
self.core.xmpp.remove_handler('custom matcher')
self.core.xmpp.register_handler(self.core.all_stanzas)
@@ -117,11 +125,14 @@ class XMLTab(Tab):
self.filter = ''
self.refresh()
- def command_dump(self, arg):
+ @command_args_parser.quoted(1)
+ def command_dump(self, args):
"""/dump <filename>"""
+ if args is None:
+ return self.core.command_help('dump')
xml = self.core.xml_buffer.messages[:]
text = '\n'.join(('%s %s' % (msg.str_time, clean_text(msg.txt)) for msg in xml))
- filename = os.path.expandvars(os.path.expanduser(arg))
+ filename = os.path.expandvars(os.path.expanduser(args[0]))
try:
with open(filename, 'w') as fd:
fd.write(text)
@@ -151,7 +162,8 @@ class XMLTab(Tab):
def on_scroll_down(self):
return self.text_win.scroll_down(self.text_win.height-1)
- def command_clear(self, args):
+ @command_args_parser.ignored
+ def command_clear(self):
"""
/clear
"""