mirror of https://github.com/Mikaela/Limnoria.git
Allow irc.error() to be called with no arguments and act as if ArgumentError was raised.
This commit is contained in:
parent
59151542b9
commit
28fe96c833
|
@ -432,6 +432,7 @@ class IrcObjectProxy(RichReplyMethods):
|
||||||
self.args = copy.deepcopy(args)
|
self.args = copy.deepcopy(args)
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
self.finished = False # Used in _callInvalidCommands.
|
self.finished = False # Used in _callInvalidCommands.
|
||||||
|
self.commandMethod = None # Used in error.
|
||||||
self._resetReplyAttributes()
|
self._resetReplyAttributes()
|
||||||
if not args:
|
if not args:
|
||||||
self.finalEvaled = True
|
self.finalEvaled = True
|
||||||
|
@ -473,21 +474,25 @@ class IrcObjectProxy(RichReplyMethods):
|
||||||
|
|
||||||
def _callCommand(self, name, command, cb):
|
def _callCommand(self, name, command, cb):
|
||||||
try:
|
try:
|
||||||
cb.callCommand(command, self, self.msg, self.args)
|
self.commandMethod = command
|
||||||
except (getopt.GetoptError, ArgumentError):
|
try:
|
||||||
self.reply(formatArgumentError(command, name=name))
|
cb.callCommand(command, self, self.msg, self.args)
|
||||||
except CannotNest, e:
|
except (getopt.GetoptError, ArgumentError):
|
||||||
if not isinstance(self.irc, irclib.Irc):
|
self.reply(formatArgumentError(command, name=name))
|
||||||
self.error('Command %r cannot be nested.' % name)
|
except CannotNest, e:
|
||||||
except (SyntaxError, Error), e:
|
if not isinstance(self.irc, irclib.Irc):
|
||||||
cb.log.info('Error return: %s', e)
|
self.error('Command %r cannot be nested.' % name)
|
||||||
self.error(str(e))
|
except (SyntaxError, Error), e:
|
||||||
except Exception, e:
|
cb.log.info('Error return: %s', e)
|
||||||
cb.log.exception('Uncaught exception:')
|
self.error(str(e))
|
||||||
if conf.supybot.reply.detailedErrors():
|
except Exception, e:
|
||||||
self.error(utils.exnToString(e))
|
cb.log.exception('Uncaught exception:')
|
||||||
else:
|
if conf.supybot.reply.detailedErrors():
|
||||||
self.replyError()
|
self.error(utils.exnToString(e))
|
||||||
|
else:
|
||||||
|
self.replyError()
|
||||||
|
finally:
|
||||||
|
self.commandMethod = None
|
||||||
|
|
||||||
def finalEval(self):
|
def finalEval(self):
|
||||||
assert not self.finalEvaled, 'finalEval called twice.'
|
assert not self.finalEvaled, 'finalEval called twice.'
|
||||||
|
@ -642,12 +647,19 @@ class IrcObjectProxy(RichReplyMethods):
|
||||||
self.args[self.counter] = s
|
self.args[self.counter] = s
|
||||||
self.evalArgs()
|
self.evalArgs()
|
||||||
|
|
||||||
def error(self, s, private=None, notice=None, **kwargs):
|
def error(self, s='', private=None, notice=None, **kwargs):
|
||||||
if not isinstance(self.irc, irclib.Irc):
|
if s:
|
||||||
self.irc.error(s, private)
|
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:
|
else:
|
||||||
self.irc.queueMsg(error(self.msg, s, private=private,
|
# No argument, let's raise ArgumentError.
|
||||||
notice=notice, **kwargs))
|
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
|
self.finished = True
|
||||||
|
|
||||||
def getRealIrc(self):
|
def getRealIrc(self):
|
||||||
|
|
|
@ -266,6 +266,9 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.reply.errorInPrivate.setValue(original)
|
conf.supybot.reply.errorInPrivate.setValue(original)
|
||||||
|
|
||||||
|
def testErrorNoArgumentIsArgumentError(self):
|
||||||
|
self.assertHelp('eval irc.error()')
|
||||||
|
|
||||||
def testErrorWithNotice(self):
|
def testErrorWithNotice(self):
|
||||||
try:
|
try:
|
||||||
original = conf.supybot.reply.errorWithNotice()
|
original = conf.supybot.reply.errorWithNotice()
|
||||||
|
|
Loading…
Reference in New Issue