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()
callBefore = utils.Nothing()
def __cmp__(self, other):
return 1 # We should always be the last plugin.
def __lt__(self, other):
return False # We should always be the last plugin.
def invalidCommand(self, irc, msg, tokens):
self.log.debug('Misc.invalidCommand called (tokens %s)', tokens)

View File

@ -228,8 +228,8 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
callAfter = utils.Nothing()
callBefore = utils.Everything()
def __cmp__(self, other):
return -1 # We should always be the first plugin.
def __lt__(self, other):
return True # We should always be the first plugin.
def _getIrc(self, network):
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
# called before and after, respectively. We may, at some future point,
# remove priority entirely.
def __cmp__(self, other):
def __lt__(self, other):
selfName = self.name()
otherName = other.name()
# 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.
if isinstance(other, Privmsg):
if otherName in self.callAfter or selfName in other.callBefore:
return 1
elif otherName in self.callBefore or selfName in other.callAfter:
return -1
return self.__parent.__cmp__(other)
if other.name() in self.callBefore or \
self.name() in other.callAfter:
return True
else:
return False
return self.__parent.__lt__(other)
def __call__(self, irc, msg):
if msg.command == 'PRIVMSG':

View File

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