diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-02-10 12:39:15 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-02-10 12:39:15 +0100 |
commit | 3dbb6590d3fab0ffb8ec7e66f0ecbe2701ce8d75 (patch) | |
tree | 516710779a129372e4dcf49eedf915948a5fb3db /src | |
parent | 538c843ec704fea18107f875aad0e14eebd1875e (diff) | |
download | poezio-3dbb6590d3fab0ffb8ec7e66f0ecbe2701ce8d75.tar.gz poezio-3dbb6590d3fab0ffb8ec7e66f0ecbe2701ce8d75.tar.bz2 poezio-3dbb6590d3fab0ffb8ec7e66f0ecbe2701ce8d75.tar.xz poezio-3dbb6590d3fab0ffb8ec7e66f0ecbe2701ce8d75.zip |
Make the shell split do a normal split if the syntax is wrong
Diffstat (limited to 'src')
-rw-r--r-- | src/common.py | 13 | ||||
-rw-r--r-- | src/core.py | 1 | ||||
-rw-r--r-- | src/tabs.py | 33 |
3 files changed, 20 insertions, 27 deletions
diff --git a/src/common.py b/src/common.py index 141b67be..f910892d 100644 --- a/src/common.py +++ b/src/common.py @@ -41,6 +41,7 @@ import subprocess import curses import sys import time +import shlex ROOM_STATE_NONE = 11 ROOM_STATE_CURRENT = 10 @@ -192,3 +193,15 @@ def datetime_tuple(timestamp): dst = timedelta(seconds=time.altzone) ret -= dst return ret + +def shell_split(string): + sh = shlex.shlex(string, posix=True) + ret = list() + try: + w = sh.get_token() + while w: + ret.append(w) + w = sh.get_token() + return ret + except ValueError: + return string.split() diff --git a/src/core.py b/src/core.py index b96315c0..a9ea5af5 100644 --- a/src/core.py +++ b/src/core.py @@ -23,7 +23,6 @@ from time import sleep import os import re import sys -import shlex import curses import threading import traceback diff --git a/src/tabs.py b/src/tabs.py index 5a27902e..70c02911 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -35,9 +35,9 @@ import windows import theme import curses import difflib -import shlex import text_buffer import string +import common from sleekxmpp.xmlstream.stanzabase import JID from config import config @@ -381,10 +381,7 @@ class MucTab(ChatTab): self.core.refresh_window() def command_info(self, arg): - try: - args = shlex.split(arg) - except ValueError as error: - return self.core.information(str(error), _("Error")) + args = common.shell_split(arg) if len(args) != 1: return self.core.information("Info command takes only 1 argument") user = self.get_room().get_user_by_name(args[0]) @@ -442,10 +439,7 @@ class MucTab(ChatTab): """ /nick <nickname> """ - try: - args = shlex.split(arg) - except ValueError as error: - return self.core.information(str(error), _("Error")) + args = common.shell_split(arg) if len(args) != 1: return nick = args[0] @@ -459,7 +453,6 @@ class MucTab(ChatTab): /part [msg] """ args = arg.split() - reason = None room = self.get_room() if len(args): msg = ' '.join(args) @@ -473,10 +466,7 @@ class MucTab(ChatTab): """ /query <nick> [message] """ - try: - args = shlex.split(arg) - except ValueError as error: - return self.core.information(str(error), _("Error")) + args = common.shell_split(arg) if len(args) < 1: return nick = args[0] @@ -505,10 +495,7 @@ class MucTab(ChatTab): """ /kick <nick> [reason] """ - try: - args = shlex.split(arg) - except ValueError as error: - return self.core.information(str(error), _("Error")) + args = common.shell_split(arg) if len(args) < 1: self.core.command_help('kick') return @@ -530,10 +517,7 @@ class MucTab(ChatTab): """ /ignore <nick> """ - try: - args = shlex.split(arg) - except ValueError as error: - return self.core.information(str(error), _("Error")) + args = common.shell_split(arg) if len(args) != 1: self.core.command_help('ignore') return @@ -551,10 +535,7 @@ class MucTab(ChatTab): """ /unignore <nick> """ - try: - args = shlex.split(arg) - except ValueError as error: - return self.core.information(str(error), _("Error")) + args = common.shell_split(arg) if len(args) != 1: self.core.command_help('unignore') return |