3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

utils.parseModes: be a bit more fault-tolerant

- Log "mode requires an argument but none was found" errors to warning, and skip the mode instead of failing completely.
- Assign a fallback value for 'prefix', checking to make sure it exists and raising ValueError (not UnboundLocalError) when it doesn't.
This commit is contained in:
James Lu 2015-07-08 22:42:04 -07:00
parent 20772e5429
commit 35f8a0e25f

View File

@ -94,6 +94,7 @@ def parseModes(irc, target, args):
# C = Mode that changes a setting and only has a parameter when set.
# D = Mode that changes a setting and never has a parameter.
usermodes = not isChannel(target)
prefix = ''
modestring = args[0]
if not modestring:
return ValueError('No modes supplied in parseModes query: %r' % modes)
@ -109,8 +110,11 @@ def parseModes(irc, target, args):
if mode in '+-':
prefix = mode
else:
if not prefix:
raise ValueError('Invalid query %r: mode char given without preceding prefix.' % modestring)
arg = None
log.debug('Current mode: %s%s; args left: %s', prefix, mode, args)
try:
if mode in (supported_modes['*A'] + supported_modes['*B']):
# Must have parameter.
log.debug('Mode %s: This mode must have parameter.', mode)
@ -123,6 +127,11 @@ def parseModes(irc, target, args):
# Only has parameter when setting.
log.debug('Mode %s: Only has parameter when setting.', mode)
arg = args.pop(0)
except IndexError:
log.warning('(%s/%s) Error while parsing mode %r: mode requires an '
'argument but none was found. (modestring: %r)',
irc.name, target, mode, modestring)
continue # Skip this mode; don't error out completely.
res.append((prefix + mode, arg))
return res