mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
callbacks: add comments to findCallbacksForArgs.
This commit is contained in:
parent
f253da049d
commit
fe84bfbbb6
@ -775,14 +775,18 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
(a list of strings) and the plugins for which it was a command."""
|
(a list of strings) and the plugins for which it was a command."""
|
||||||
assert isinstance(args, list)
|
assert isinstance(args, list)
|
||||||
args = list(map(canonicalName, args))
|
args = list(map(canonicalName, args))
|
||||||
|
|
||||||
|
# Find a list maxL such that maxL = args[0:n] for the largest n
|
||||||
|
# possible such that maxL is a command.
|
||||||
cbs = []
|
cbs = []
|
||||||
maxL = []
|
maxL = []
|
||||||
for cb in self.irc.callbacks:
|
for cb in self.irc.callbacks:
|
||||||
if not hasattr(cb, 'getCommand'):
|
if not hasattr(cb, 'getCommand'):
|
||||||
continue
|
continue
|
||||||
L = cb.getCommand(args)
|
L = cb.getCommand(args)
|
||||||
#log.debug('%s.getCommand(%r) returned %r', cb.name(), args, L)
|
|
||||||
if L and L >= maxL:
|
if L and L >= maxL:
|
||||||
|
# equivalent to "L and len(L) >= len(maxL)", because L and maxL
|
||||||
|
# are both "prefixes" of the same list.
|
||||||
maxL = L
|
maxL = L
|
||||||
cbs.append((cb, L))
|
cbs.append((cb, L))
|
||||||
assert isinstance(L, list), \
|
assert isinstance(L, list), \
|
||||||
@ -791,7 +795,11 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
'getCommand must return a prefix of the args given. ' \
|
'getCommand must return a prefix of the args given. ' \
|
||||||
'(args given: %r, returned: %r)' % (args, L)
|
'(args given: %r, returned: %r)' % (args, L)
|
||||||
log.debug('findCallbacksForArgs: %r', cbs)
|
log.debug('findCallbacksForArgs: %r', cbs)
|
||||||
|
|
||||||
|
# Filter out all the entries in cbs that are smaller than maxL (ie.
|
||||||
|
# maxL contains them, with more items at the end.)
|
||||||
cbs = [cb for (cb, L) in cbs if L == maxL]
|
cbs = [cb for (cb, L) in cbs if L == maxL]
|
||||||
|
|
||||||
if len(maxL) == 1:
|
if len(maxL) == 1:
|
||||||
# Special case: one arg determines the callback. In this case, we
|
# Special case: one arg determines the callback. In this case, we
|
||||||
# have to check, in order:
|
# have to check, in order:
|
||||||
|
Loading…
Reference in New Issue
Block a user