Made Aliases disambiguate themselves, and made that API in Owner public.

This commit is contained in:
Jeremy Fincher 2003-11-12 02:18:22 +00:00
parent b8c94599fc
commit e4f912fc51
3 changed files with 10 additions and 5 deletions

View File

@ -144,6 +144,8 @@ def makeNewAlias(name, alias):
return True
return False
everythingReplace(tokens)
Owner = irc.getCallback('Owner')
Owner.disambiguate(irc, tokens)
self.Proxy(irc.irc, msg, tokens)
f = types.FunctionType(f.func_code, f.func_globals,
name, closure=f.func_closure)

View File

@ -88,7 +88,9 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
setattr(self.__class__, 'exec', self.__class__._exec)
self.defaultPlugins = {}
def _disambiguate(self, irc, tokens, ambiguousCommands):
def disambiguate(self, irc, tokens, ambiguousCommands=None):
if ambiguousCommands is None:
ambiguousCommands = {}
if tokens:
command = callbacks.canonicalName(tokens[0])
if command in self.defaultPlugins:
@ -104,7 +106,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
ambiguousCommands[command] = names
for elt in tokens:
if isinstance(elt, list):
self._disambiguate(irc, elt, ambiguousCommands)
self.disambiguate(irc, elt, ambiguousCommands)
def doPrivmsg(self, irc, msg):
callbacks.Privmsg.handled = False
@ -118,7 +120,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
irc.queueMsg(callbacks.error(msg, str(e)))
return
ambiguousCommands = {}
self._disambiguate(irc, tokens, ambiguousCommands)
self.disambiguate(irc, tokens, ambiguousCommands)
if ambiguousCommands:
if len(ambiguousCommands) == 1: # Common case.
(command, names) = ambiguousCommands.popitem()

View File

@ -231,7 +231,7 @@ def tokenize(s):
_lastTokenized = None
_lastTokenizedResult = None
raise SyntaxError, str(e)
#debug.msg('tokenize took %s seconds.' % (time.time() - start), 'verbose')
debug.msg('tokenize took %s seconds.' % (time.time() - start), 'verbose')
return copy.deepcopy(_lastTokenizeResult)
def getCommands(tokens):
@ -328,7 +328,8 @@ class IrcObjectProxy:
self._callInvalidCommands()
else:
try:
assert len(cbs) == 1
assert len(cbs) == 1, \
'Got command that wasn\'t disambiguated: %s' % name
del self.args[0]
cb = cbs[0]
anticap = ircdb.makeAntiCapability(name)