mirror of
https://github.com/progval/Limnoria.git
synced 2025-05-05 09:50:52 -05:00
Config: Differentiate between (un)settable config vars
Config.{set,get,default} should only be called on settable config variables. Detect whether the given argument is settable and emit an error if not. This avoids an uncaught exception.
This commit is contained in:
parent
730bca616b
commit
feeded6135
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2002-2005, Jeremiah Fincher
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
||||||
|
# Copyright (c) 2009, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -85,7 +86,6 @@ def _hupHandler(sig, frame):
|
|||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
signal.signal(signal.SIGHUP, _hupHandler)
|
signal.signal(signal.SIGHUP, _hupHandler)
|
||||||
|
|
||||||
|
|
||||||
def getConfigVar(irc, msg, args, state):
|
def getConfigVar(irc, msg, args, state):
|
||||||
name = args[0]
|
name = args[0]
|
||||||
if name.startswith('conf.'):
|
if name.startswith('conf.'):
|
||||||
@ -100,6 +100,13 @@ def getConfigVar(irc, msg, args, state):
|
|||||||
state.errorInvalid('configuration variable', str(e))
|
state.errorInvalid('configuration variable', str(e))
|
||||||
addConverter('configVar', getConfigVar)
|
addConverter('configVar', getConfigVar)
|
||||||
|
|
||||||
|
def getSettableConfigVar(irc, msg, args, state):
|
||||||
|
getConfigVar(irc, msg, args, state)
|
||||||
|
if not hasattr(state.args[-1], 'set'):
|
||||||
|
state.errorInvalid('settable configuration variable',
|
||||||
|
state.args[-1]._name)
|
||||||
|
addConverter('settableConfigVar', getSettableConfigVar)
|
||||||
|
|
||||||
class Config(callbacks.Plugin):
|
class Config(callbacks.Plugin):
|
||||||
def callCommand(self, command, irc, msg, *args, **kwargs):
|
def callCommand(self, command, irc, msg, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
@ -195,7 +202,8 @@ class Config(callbacks.Plugin):
|
|||||||
self._setValue(irc, msg, group, value)
|
self._setValue(irc, msg, group, value)
|
||||||
else:
|
else:
|
||||||
self._getValue(irc, msg, group)
|
self._getValue(irc, msg, group)
|
||||||
channel = wrap(channel, ['channel', 'configVar', additional('text')])
|
channel = wrap(channel, ['channel', 'settableConfigVar',
|
||||||
|
additional('text')])
|
||||||
|
|
||||||
def config(self, irc, msg, args, group, value):
|
def config(self, irc, msg, args, group, value):
|
||||||
"""<name> [<value>]
|
"""<name> [<value>]
|
||||||
@ -208,7 +216,7 @@ class Config(callbacks.Plugin):
|
|||||||
self._setValue(irc, msg, group, value)
|
self._setValue(irc, msg, group, value)
|
||||||
else:
|
else:
|
||||||
self._getValue(irc, msg, group)
|
self._getValue(irc, msg, group)
|
||||||
config = wrap(config, ['configVar', additional('text')])
|
config = wrap(config, ['settableConfigVar', additional('text')])
|
||||||
|
|
||||||
def help(self, irc, msg, args, group):
|
def help(self, irc, msg, args, group):
|
||||||
"""<name>
|
"""<name>
|
||||||
@ -236,7 +244,7 @@ class Config(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
v = group.__class__(group._default, '')
|
v = group.__class__(group._default, '')
|
||||||
irc.reply(str(v))
|
irc.reply(str(v))
|
||||||
default = wrap(default, ['configVar'])
|
default = wrap(default, ['settableConfigVar'])
|
||||||
|
|
||||||
def reload(self, irc, msg, args):
|
def reload(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2002-2005, Jeremiah Fincher
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
||||||
|
# Copyright (c) 2009, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -77,7 +78,7 @@ class ConfigTestCase(ChannelPluginTestCase):
|
|||||||
self.assertRegexp('config supybot.repl', 'not a valid')
|
self.assertRegexp('config supybot.repl', 'not a valid')
|
||||||
self.assertRegexp('config supybot.reply.withNickPrefix 123',
|
self.assertRegexp('config supybot.reply.withNickPrefix 123',
|
||||||
'True or False')
|
'True or False')
|
||||||
|
self.assertRegexp('config supybot.replies foo', 'settable')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user