diff --git a/plugins/ChannelStats.py b/plugins/ChannelStats.py index aca9fecd4..b1f78d740 100644 --- a/plugins/ChannelStats.py +++ b/plugins/ChannelStats.py @@ -104,7 +104,7 @@ class ChannelStat(irclib.IrcCommandDispatcher): self._values = ['actions', 'chars', 'frowns', 'joins', 'kicks','modes', 'msgs', 'parts', 'quits', 'smileys', 'topics', 'words'] def values(self): - return map(curry(getattr, self), self._values) + return map(utils.curry(getattr, self), self._values) def addMsg(self, msg): self.msgs += 1 diff --git a/src/fix.py b/src/fix.py index 47e6d2a9f..a65f1cf97 100644 --- a/src/fix.py +++ b/src/fix.py @@ -39,8 +39,8 @@ __revision__ = "$Id$" __all__ = [] -exported = ['ignore', 'catch', 'reviter', 'window', 'group', - 'partition', 'any', 'all', 'rsplit', 'curry'] +exported = ['ignore', 'reviter', 'window', 'group', 'sorted', + 'partition', 'any', 'all', 'rsplit'] import new import string @@ -61,19 +61,10 @@ def choice(iterable): return ret random.choice = choice -curry = new.instancemethod - def ignore(*args, **kwargs): """Simply ignore the arguments sent to it.""" pass -def catch(f, *args, **kwargs): - """Catches all exceptions raises by f.""" - try: - return f(*args, **kwargs) - except: - return None - def reviter(L): """Iterates through a list in reverse.""" for i in xrange(len(L) - 1, -1, -1): @@ -177,6 +168,14 @@ def rsplit(s, sep=None, maxsplit=-1): L.reverse() return [s[::-1] for s in L] +def sorted(iterable, cmp=None, key=None, reverse=False): + L = list(iterable) +## if key is None: +## L.sort(cmp) +## else: +## # Oops, we don't have sortBy. Let's come back to this.utils. +## utils.sortBy(key + import operator def itemgetter(i): return lambda x: x[i] diff --git a/src/irclib.py b/src/irclib.py index d5c332bc1..5af74a96f 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -279,7 +279,7 @@ class IrcState(IrcCommandDispatcher): self.nicksToHostmasks = ircutils.IrcDict() def __getstate__(self): - return map(curry(getattr, self), self.__slots__) + return map(utils.curry(getattr, self), self.__slots__) def __setstate__(self, t): for (name, value) in zip(self.__slots__, t): diff --git a/src/utils.py b/src/utils.py index 3f3cf0b3b..23c7a2c5e 100755 --- a/src/utils.py +++ b/src/utils.py @@ -53,6 +53,8 @@ from itertools import imap, ifilter from structures import TwoWayDictionary +curry = new.instancemethod + def normalizeWhitespace(s): """Normalizes the whitespace in a string; \s+ becomes one space.""" return ' '.join(s.split()) @@ -619,7 +621,6 @@ class InsensitivePreservingDict(UserDict.DictMixin, object): def __reduce__(self): return (self.__class__, (dict(self.data.values()),)) - if __name__ == '__main__': import sys, doctest doctest.testmod(sys.modules['__main__'])