From 3dbb6590d3fab0ffb8ec7e66f0ecbe2701ce8d75 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Thu, 10 Feb 2011 12:39:15 +0100 Subject: Make the shell split do a normal split if the syntax is wrong --- src/common.py | 13 +++++++++++++ src/core.py | 1 - 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 """ - 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 [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 [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 """ - 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 """ - 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 -- cgit v1.2.3