Changed to __lt__ instead of __cmp__ -- it's simpler and doesn't screw with equality.

This commit is contained in:
Jeremy Fincher 2004-09-10 07:27:42 +00:00
parent 56cf248302
commit ee4768634f
4 changed files with 18 additions and 17 deletions

View File

@ -77,8 +77,8 @@ class Misc(callbacks.Privmsg):
callAfter = utils.Everything() callAfter = utils.Everything()
callBefore = utils.Nothing() callBefore = utils.Nothing()
def __cmp__(self, other): def __lt__(self, other):
return 1 # We should always be the last plugin. return False # We should always be the last plugin.
def invalidCommand(self, irc, msg, tokens): def invalidCommand(self, irc, msg, tokens):
self.log.debug('Misc.invalidCommand called (tokens %s)', tokens) self.log.debug('Misc.invalidCommand called (tokens %s)', tokens)

View File

@ -228,8 +228,8 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
callAfter = utils.Nothing() callAfter = utils.Nothing()
callBefore = utils.Everything() callBefore = utils.Everything()
def __cmp__(self, other): def __lt__(self, other):
return -1 # We should always be the first plugin. return True # We should always be the first plugin.
def _getIrc(self, network): def _getIrc(self, network):
network = network.lower() network = network.lower()

View File

@ -933,18 +933,19 @@ class Privmsg(irclib.IrcCallback):
# attributes which are lists of plugin names which the plugin should be # attributes which are lists of plugin names which the plugin should be
# called before and after, respectively. We may, at some future point, # called before and after, respectively. We may, at some future point,
# remove priority entirely. # remove priority entirely.
def __cmp__(self, other): def __lt__(self, other):
selfName = self.name() selfName = self.name()
otherName = other.name() otherName = other.name()
# We can't be certain of the order the callbacks list is in, so we # We can't be certain of the order the callbacks list is in, so we
# can't be certain that our __cmp__ is the most specific one, so # can't be certain that our __lt__ is the most specific one, so
# we basically run the other callback's as well. # we basically run the other callback's as well.
if isinstance(other, Privmsg): if isinstance(other, Privmsg):
if otherName in self.callAfter or selfName in other.callBefore: if other.name() in self.callBefore or \
return 1 self.name() in other.callAfter:
elif otherName in self.callBefore or selfName in other.callAfter: return True
return -1 else:
return self.__parent.__cmp__(other) return False
return self.__parent.__lt__(other)
def __call__(self, irc, msg): def __call__(self, irc, msg):
if msg.command == 'PRIVMSG': if msg.command == 'PRIVMSG':

View File

@ -82,19 +82,19 @@ class IrcCallback(IrcCommandDispatcher):
__firewalled__ = {'die': None, __firewalled__ = {'die': None,
'reset': None, 'reset': None,
'__call__': None, '__call__': None,
'__cmp__': lambda self: 0, '__lt__': lambda self: 0,
'inFilter': lambda self, irc, msg: msg, 'inFilter': lambda self, irc, msg: msg,
'outFilter': lambda self, irc, msg: msg, 'outFilter': lambda self, irc, msg: msg,
'name': lambda self: self.__class__.__name__,} 'name': lambda self: self.__class__.__name__,}
def __cmp__(self, other): def __lt__(self, other):
if isinstance(other, IrcCallback): if isinstance(other, IrcCallback):
ret = cmp(self.priority, other.priority) ret = self.priority < other.priority
if ret == 0: if not ret:
ret = cmp(self.name(), other.name()) ret = self.name() < other.name()
return ret return ret
else: else:
return super(IrcCallback, self).__cmp__(other) return super(IrcCallback, self).__lt__(other)
def name(self): def name(self):
"""Returns the name of the callback.""" """Returns the name of the callback."""