mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-30 23:09:23 +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:
parent
20772e5429
commit
35f8a0e25f
9
utils.py
9
utils.py
@ -94,6 +94,7 @@ def parseModes(irc, target, args):
|
|||||||
# C = Mode that changes a setting and only has a parameter when set.
|
# C = Mode that changes a setting and only has a parameter when set.
|
||||||
# D = Mode that changes a setting and never has a parameter.
|
# D = Mode that changes a setting and never has a parameter.
|
||||||
usermodes = not isChannel(target)
|
usermodes = not isChannel(target)
|
||||||
|
prefix = ''
|
||||||
modestring = args[0]
|
modestring = args[0]
|
||||||
if not modestring:
|
if not modestring:
|
||||||
return ValueError('No modes supplied in parseModes query: %r' % modes)
|
return ValueError('No modes supplied in parseModes query: %r' % modes)
|
||||||
@ -109,8 +110,11 @@ def parseModes(irc, target, args):
|
|||||||
if mode in '+-':
|
if mode in '+-':
|
||||||
prefix = mode
|
prefix = mode
|
||||||
else:
|
else:
|
||||||
|
if not prefix:
|
||||||
|
raise ValueError('Invalid query %r: mode char given without preceding prefix.' % modestring)
|
||||||
arg = None
|
arg = None
|
||||||
log.debug('Current mode: %s%s; args left: %s', prefix, mode, args)
|
log.debug('Current mode: %s%s; args left: %s', prefix, mode, args)
|
||||||
|
try:
|
||||||
if mode in (supported_modes['*A'] + supported_modes['*B']):
|
if mode in (supported_modes['*A'] + supported_modes['*B']):
|
||||||
# Must have parameter.
|
# Must have parameter.
|
||||||
log.debug('Mode %s: This mode must have parameter.', mode)
|
log.debug('Mode %s: This mode must have parameter.', mode)
|
||||||
@ -123,6 +127,11 @@ def parseModes(irc, target, args):
|
|||||||
# Only has parameter when setting.
|
# Only has parameter when setting.
|
||||||
log.debug('Mode %s: Only has parameter when setting.', mode)
|
log.debug('Mode %s: Only has parameter when setting.', mode)
|
||||||
arg = args.pop(0)
|
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))
|
res.append((prefix + mode, arg))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user