mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Fix for bug #1031800, uncaught exceptions in Config commands.
This commit is contained in:
parent
f3d0670175
commit
3ee4223bda
@ -54,8 +54,8 @@ import supybot.callbacks as callbacks
|
|||||||
# Now, to setup the registry.
|
# Now, to setup the registry.
|
||||||
###
|
###
|
||||||
|
|
||||||
class InvalidRegistryName(callbacks.Error):
|
#class InvalidRegistryName(callbacks.Error):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def getWrapper(name):
|
def getWrapper(name):
|
||||||
parts = registry.split(name)
|
parts = registry.split(name)
|
||||||
@ -65,8 +65,11 @@ def getWrapper(name):
|
|||||||
while parts:
|
while parts:
|
||||||
try:
|
try:
|
||||||
group = group.get(parts.pop(0))
|
group = group.get(parts.pop(0))
|
||||||
except registry.NonExistentRegistryEntry:
|
# We'll catch registry.InvalidRegistryName and re-raise it here so
|
||||||
raise InvalidRegistryName, name
|
# that we have a useful error message for the user.
|
||||||
|
except (registry.NonExistentRegistryEntry,
|
||||||
|
registry.InvalidRegistryName):
|
||||||
|
raise registry.InvalidRegistryName, name
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def getCapability(name):
|
def getCapability(name):
|
||||||
@ -97,12 +100,13 @@ if os.name == 'posix':
|
|||||||
class Config(callbacks.Privmsg):
|
class Config(callbacks.Privmsg):
|
||||||
def callCommand(self, name, irc, msg, *L, **kwargs):
|
def callCommand(self, name, irc, msg, *L, **kwargs):
|
||||||
#XXX For some reason, that confuses jamessan, InvalidRegistryName
|
#XXX For some reason, that confuses jamessan, InvalidRegistryName
|
||||||
# is not really being caught here, but it is caught if we
|
# is not really being caught here, but registry.InvalidRegistryName
|
||||||
# attempt to catch it in the individual command methods.
|
# is. So, we'll just re-raise registry.InvalidRegsitryName instead
|
||||||
|
# of using Config.InvalidRegistryName
|
||||||
try:
|
try:
|
||||||
super(Config, self).callCommand(name, irc, msg, *L, **kwargs)
|
super(Config, self).callCommand(name, irc, msg, *L, **kwargs)
|
||||||
except InvalidRegistryName, e:
|
except registry.InvalidRegistryName, e:
|
||||||
irc.errorInvalid('configuration variable', e.args[0])
|
irc.errorInvalid('configuration variable', str(e))
|
||||||
except registry.InvalidRegistryValue, e:
|
except registry.InvalidRegistryValue, e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
|
|
||||||
@ -133,10 +137,7 @@ class Config(callbacks.Privmsg):
|
|||||||
configuration <group>. Subgroups are indicated by a preceding @.
|
configuration <group>. Subgroups are indicated by a preceding @.
|
||||||
"""
|
"""
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
try:
|
L = self._list(name)
|
||||||
L = self._list(name)
|
|
||||||
except InvalidRegistryName, e:
|
|
||||||
irc.errorInvalid('configuration variable', e.args[0], Raise=True)
|
|
||||||
if L:
|
if L:
|
||||||
irc.reply(utils.commaAndify(L))
|
irc.reply(utils.commaAndify(L))
|
||||||
else:
|
else:
|
||||||
@ -167,13 +168,10 @@ class Config(callbacks.Privmsg):
|
|||||||
returns the current value of <name>. You may omit the leading
|
returns the current value of <name>. You may omit the leading
|
||||||
"supybot." in the name if you so choose.
|
"supybot." in the name if you so choose.
|
||||||
"""
|
"""
|
||||||
try:
|
if len(args) >= 2:
|
||||||
if len(args) >= 2:
|
self._set(irc, msg, args)
|
||||||
self._set(irc, msg, args)
|
else:
|
||||||
else:
|
self._get(irc, msg, args)
|
||||||
self._get(irc, msg, args)
|
|
||||||
except InvalidRegistryName, e:
|
|
||||||
irc.errorInvalid('configuration variable', e.args[0], Raise=True)
|
|
||||||
|
|
||||||
def channel(self, irc, msg, args):
|
def channel(self, irc, msg, args):
|
||||||
"""[<channel>] <name> [<value>]
|
"""[<channel>] <name> [<value>]
|
||||||
@ -186,10 +184,7 @@ class Config(callbacks.Privmsg):
|
|||||||
if not args:
|
if not args:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
args[0] = self._canonicalizeName(args[0])
|
args[0] = self._canonicalizeName(args[0])
|
||||||
try:
|
wrapper = getWrapper(args[0])
|
||||||
wrapper = getWrapper(args[0])
|
|
||||||
except InvalidRegistryName, e:
|
|
||||||
irc.errorInvalid('configuration variable', e.args[0], Raise=True)
|
|
||||||
if not wrapper.channelValue:
|
if not wrapper.channelValue:
|
||||||
irc.error('That configuration variable is not a channel-specific '
|
irc.error('That configuration variable is not a channel-specific '
|
||||||
'configuration variable.')
|
'configuration variable.')
|
||||||
@ -243,10 +238,7 @@ class Config(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
name = self._canonicalizeName(name)
|
name = self._canonicalizeName(name)
|
||||||
try:
|
wrapper = getWrapper(name)
|
||||||
wrapper = getWrapper(name)
|
|
||||||
except InvalidRegistryName, e:
|
|
||||||
irc.errorInvalid('configuration variable', e.args[0], Raise=True)
|
|
||||||
if hasattr(wrapper, 'help'):
|
if hasattr(wrapper, 'help'):
|
||||||
s = wrapper.help
|
s = wrapper.help
|
||||||
if hasattr(wrapper, 'value') and not wrapper._private:
|
if hasattr(wrapper, 'value') and not wrapper._private:
|
||||||
@ -262,10 +254,7 @@ class Config(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
name = self._canonicalizeName(name)
|
name = self._canonicalizeName(name)
|
||||||
try:
|
wrapper = getWrapper(name)
|
||||||
wrapper = getWrapper(name)
|
|
||||||
except InvalidRegistryName, e:
|
|
||||||
irc.errorInvalid('configuration variable', e.args[0], Raise=True)
|
|
||||||
v = wrapper.__class__(wrapper._default, '')
|
v = wrapper.__class__(wrapper._default, '')
|
||||||
irc.reply(str(v))
|
irc.reply(str(v))
|
||||||
|
|
||||||
|
@ -66,6 +66,12 @@ class ConfigTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('config default '
|
self.assertNotError('config default '
|
||||||
'supybot.replies.genericNoCapability')
|
'supybot.replies.genericNoCapability')
|
||||||
|
|
||||||
|
def testConfigErrors(self):
|
||||||
|
self.assertRegexp('config supybot.replies.', 'not a valid')
|
||||||
|
self.assertRegexp('config supybot.repl', 'not a valid')
|
||||||
|
self.assertRegexp('config supybot.reply.withNickPrefix 123',
|
||||||
|
'True or False')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user