Updated sorted for 2.4 compatibility.

This commit is contained in:
Jeremy Fincher 2004-04-20 10:04:09 +00:00
parent 85807dd077
commit ed8df0a998
2 changed files with 10 additions and 5 deletions

View File

@ -151,7 +151,7 @@ class Topic(callbacks.Privmsg):
except ValueError: except ValueError:
irc.error('The positions must be valid integers.') irc.error('The positions must be valid integers.')
return return
if utils.sorted(order) != range(num): if sorted(order) != range(num):
irc.error('Duplicate topic numbers cannot be specified.') irc.error('Duplicate topic numbers cannot be specified.')
return return
try: try:

View File

@ -394,13 +394,18 @@ def sortBy(f, L, cmp=cmp):
for (i, elt) in enumerate(L): for (i, elt) in enumerate(L):
L[i] = L[i][2] L[i] = L[i][2]
def sorted(iterable, *args, **kwargs): def sorted(iterable, cmp=None, key=None, reversed=False):
"""Returns a sorted list made from iterable. All other args are given to
list.sort unchanged."""
L = list(iterable) L = list(iterable)
L.sort(*args, **kwargs) if key is not None:
sortBy(key, L, cmp=cmp)
else:
L.sort(cmp)
if reversed:
L.reverse()
return L return L
__builtins__['sorted'] = sorted
def mktemp(suffix=''): def mktemp(suffix=''):
"""Gives a decent random string, suitable for a filename.""" """Gives a decent random string, suitable for a filename."""
import sha import sha