Fixed bug with nested plugins having the same name as themselves.

This commit is contained in:
Jeremy Fincher 2005-03-09 08:05:24 +00:00
parent 52fabfdaf7
commit 0e68a44513
2 changed files with 19 additions and 16 deletions

View File

@ -1020,33 +1020,31 @@ class Commands(BasePlugin):
return self.getCommand(command) == command
def getCommand(self, args):
assert args == map(canonicalName, args)
first = args[0]
if len(args) >= 2 and first == self.canonicalName():
command = self.getCommand(args[1:])
if command:
command.insert(0, first)
return command
for cb in self.cbs:
if first == cb.canonicalName():
command = cb.getCommand(args[1:])
if command:
command.insert(0, first)
return command
return cb.getCommand(args)
if self.isCommandMethod(first):
return [first]
elif first == self.canonicalName():
ret = self.getCommand(args[1:])
if ret:
return [first] + ret
return []
def getCommandMethod(self, command):
"""Gets the given command from this plugin."""
#print '*** %s.getCommandMethod(%r)' % (self.name(), command)
assert not isinstance(command, basestring)
assert command == map(canonicalName, command)
assert self.getCommand(command) == command
for cb in self.cbs:
if command[0] == cb.canonicalName():
return cb.getCommandMethod(command)
if len(command) > 1:
if command[0] == self.canonicalName():
return self.getCommandMethod(command[1:])
for cb in self.cbs:
if command[0] == cb.canonicalName():
return cb.getCommandMethod(command)
assert command[0] == self.canonicalName()
return self.getCommandMethod(command[1:])
else:
return getattr(self, command[0])
@ -1058,7 +1056,10 @@ class Commands(BasePlugin):
for cb in self.cbs:
name = cb.canonicalName()
for command in cb.listCommands():
commands.append(' '.join([name, command]))
if command == name:
commands.append(command)
else:
commands.append(' '.join([name, command]))
commands.sort()
return commands

View File

@ -544,11 +544,13 @@ class SourceNestedPluginTestCase(PluginTestCase):
self.assertHelp('help f')
self.assertHelp('help e g h')
self.assertHelp('help e g i j')
self.assertRegexp('list e', 'f, g h, and g i j')
self.assertRegexp('list e', 'f, g h, g i j, and same')
def testCommandSameNameAsNestedPlugin(self):
cb = self.E(self.irc)
self.irc.addCallback(cb)
self.assertResponse('e f', 'f') # Just to make sure it was loaded.
self.assertEqual(cb.getCommand(['e', 'same']), ['e', 'same'])
self.assertResponse('e same', 'same')