summaryrefslogtreecommitdiff
path: root/src/tabs/xmltab.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-11-25 16:58:26 +0100
committerFlorent Le Coz <louiz@louiz.org>2014-11-25 17:07:45 +0100
commite1808a8455aadc9fac300c68e397b712a030ae29 (patch)
treedf5ad7cf84a8e9faa4cd018189bf585ee9d7bdeb /src/tabs/xmltab.py
parent61b5c6a91e58b81811bcbf8e789b0bf112d3a416 (diff)
downloadpoezio-e1808a8455aadc9fac300c68e397b712a030ae29.tar.gz
poezio-e1808a8455aadc9fac300c68e397b712a030ae29.tar.bz2
poezio-e1808a8455aadc9fac300c68e397b712a030ae29.tar.xz
poezio-e1808a8455aadc9fac300c68e397b712a030ae29.zip
Parse command arguments using a decorator and make things more consistent
Avoid surprises with some commands accepting quoted arguments and some other not. fix #2555
Diffstat (limited to 'src/tabs/xmltab.py')
-rw-r--r--src/tabs/xmltab.py36
1 files changed, 24 insertions, 12 deletions
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
"""