changeset 204ec09ebdc1 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=204ec09ebdc1
description: Touchup for /dtmf implementation
diffstat:
src/command_system/implementation/standard.py | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diffs (19 lines):
diff -r 287eea4c6bad -r 204ec09ebdc1 src/command_system/implementation/standard.py
--- a/src/command_system/implementation/standard.py Thu Mar 18 07:37:49 2010 +0200
+++ b/src/command_system/implementation/standard.py Thu Mar 18 08:17:48 2010 +0200
@@ -173,13 +173,12 @@
gajim.connections[self.account].sendPing(self.contact)
@command
- @documentation(_("Sends DTMF events through an open audio session"))
+ @documentation(_("Send DTMF events through an open audio session"))
def dtmf(self, events):
if not self.audio_sid:
raise CommandError(_("There is no open audio session with this contact"))
# Valid values for DTMF tones are *, # or a number
- events = [event for event in events
- if event in ('*', '#') or event.isdigit()]
+ events = filter(lambda e: e in ('*', '#') or e.isdigit (), events)
if events:
session = gajim.connections[self.account].get_jingle_session(
self.contact.get_full_jid(), self.audio_sid)
changeset 287eea4c6bad in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=287eea4c6bad
description: Added a comment about command escaping and tiny touchups
diffstat:
src/command_system/errors.py | 6 +++++
src/command_system/framework.py | 4 +-
src/command_system/implementation/middleware.py | 29 +++++++++++++++---------
3 files changed, 26 insertions(+), 13 deletions(-)
diffs (97 lines):
diff -r 84266101d98c -r 287eea4c6bad src/command_system/errors.py
--- a/src/command_system/errors.py Thu Mar 18 06:52:05 2010 +0200
+++ b/src/command_system/errors.py Thu Mar 18 07:37:49 2010 +0200
@@ -45,3 +45,9 @@
Used to indicate errors occured during command execution.
"""
pass
+
+class NoCommandError(BaseError):
+ """
+ Used to indicate an inability to find the specified command.
+ """
+ pass
diff -r 84266101d98c -r 287eea4c6bad src/command_system/framework.py
--- a/src/command_system/framework.py Thu Mar 18 06:52:05 2010 +0200
+++ b/src/command_system/framework.py Thu Mar 18 07:37:49 2010 +0200
@@ -25,7 +25,7 @@
from dispatching import Dispatcher, HostDispatcher, ContainerDispatcher
from mapping import parse_arguments, adapt_arguments
-from errors import DefinitionError, CommandError
+from errors import DefinitionError, CommandError, NoCommandError
class CommandHost(object):
"""
@@ -128,7 +128,7 @@
def get_command(self, name):
command = Dispatcher.get_command(self.COMMAND_HOST, name)
if not command:
- raise CommandError("Command does not exist", name=name)
+ raise NoCommandError("Command does not exist", name=name)
return command
def list_commands(self):
diff -r 84266101d98c -r 287eea4c6bad src/command_system/implementation/middleware.py
--- a/src/command_system/implementation/middleware.py Thu Mar 18 06:52:05 2010 +0200
+++ b/src/command_system/implementation/middleware.py Thu Mar 18 07:37:49 2010 +0200
@@ -26,7 +26,7 @@
from common import gajim
from ..framework import CommandProcessor
-from ..errors import CommandError
+from ..errors import CommandError, NoCommandError
class ChatCommandProcessor(CommandProcessor):
"""
@@ -44,33 +44,40 @@
def execute_command(self, name, arguments):
try:
super(ChatCommandProcessor, self).execute_command(name, arguments)
+ except NoCommandError, error:
+ details = dict(name=error.name, message=error.message)
+ message = "%(name)s: %(message)s\n" % details
+ message += "Try using the //%(name)s or /say /%(name)s " % details
+ message += "construct if you intended to send it as a text."
+ self.echo(message, 'error')
except CommandError, error:
- self.echo("%s: %s" %(error.name, error.message), 'error')
+ self.echo("%s: %s" % (error.name, error.message), 'error')
except Exception:
self.echo("An error occured while trying to execute the command", 'error')
print_exc()
def looks_like_command(self, text, body, name, arguments):
- # Command escape stuff ggoes here. If text was prepended by the command
- # prefix twice, like //not_a_command (if prefix is set to /) then it
- # will be escaped, that is sent just as a regular message with one (only
- # one) prefix removed, so message will be /not_a_command.
+ # Command escape stuff ggoes here. If text was prepended by the
+ # command prefix twice, like //not_a_command (if prefix is set
+ # to /) then it will be escaped, that is sent just as a regular
+ # message with one (only one) prefix removed, so message will be
+ # /not_a_command.
if body.startswith(self.COMMAND_PREFIX):
self.send(body)
return True
def command_preprocessor(self, command, name, arguments, args, kwargs):
- # If command argument contain h or help option - forward it to the /help
- # command. Dont forget to pass self, as all commands are unbound. And
- # also don't forget to print output.
+ # If command argument contain h or help option - forward it to
+ # the /help command. Dont forget to pass self, as all commands
+ # are unbound. And also don't forget to print output.
if 'h' in kwargs or 'help' in kwargs:
help = self.get_command('help')
self.echo(help(self, name))
return True
def command_postprocessor(self, command, name, arguments, args, kwargs, value):
- # If command returns a string - print it to a user. A convenient and
- # sufficient in most simple cases shortcut to a using echo.
+ # If command returns a string - print it to a user. A convenient
+ # and sufficient in most simple cases shortcut to a using echo.
if value and isinstance(value, StringTypes):
self.echo(value)