Allow irc.error() to be called with no arguments and act as if ArgumentError was raised.

This commit is contained in:
Jeremy Fincher 2004-04-21 04:31:42 +00:00
parent 59151542b9
commit 28fe96c833
2 changed files with 35 additions and 20 deletions

View File

@ -432,6 +432,7 @@ class IrcObjectProxy(RichReplyMethods):
self.args = copy.deepcopy(args)
self.counter = 0
self.finished = False # Used in _callInvalidCommands.
self.commandMethod = None # Used in error.
self._resetReplyAttributes()
if not args:
self.finalEvaled = True
@ -472,6 +473,8 @@ class IrcObjectProxy(RichReplyMethods):
cb.invalidCommand(self, self.msg, self.args)
def _callCommand(self, name, command, cb):
try:
self.commandMethod = command
try:
cb.callCommand(command, self, self.msg, self.args)
except (getopt.GetoptError, ArgumentError):
@ -488,6 +491,8 @@ class IrcObjectProxy(RichReplyMethods):
self.error(utils.exnToString(e))
else:
self.replyError()
finally:
self.commandMethod = None
def finalEval(self):
assert not self.finalEvaled, 'finalEval called twice.'
@ -642,12 +647,19 @@ class IrcObjectProxy(RichReplyMethods):
self.args[self.counter] = s
self.evalArgs()
def error(self, s, private=None, notice=None, **kwargs):
def error(self, s='', private=None, notice=None, **kwargs):
if s:
if not isinstance(self.irc, irclib.Irc):
self.irc.error(s, private)
else:
self.irc.queueMsg(error(self.msg, s, private=private,
notice=notice, **kwargs))
else:
# No argument, let's raise ArgumentError.
if self.commandMethod is not None:
# We can recurse here because it only gets called once.
self.error(formatArgumentError(self.commandMethod),
private=private, notice=notice, **kwargs)
self.finished = True
def getRealIrc(self):

View File

@ -266,6 +266,9 @@ class PrivmsgTestCase(ChannelPluginTestCase):
finally:
conf.supybot.reply.errorInPrivate.setValue(original)
def testErrorNoArgumentIsArgumentError(self):
self.assertHelp('eval irc.error()')
def testErrorWithNotice(self):
try:
original = conf.supybot.reply.errorWithNotice()