mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Removed catch, moved curry to utils.py
This commit is contained in:
parent
69c7c76e3a
commit
96838d0dbc
@ -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
|
||||
|
21
src/fix.py
21
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]
|
||||
|
@ -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):
|
||||
|
@ -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__'])
|
||||
|
Loading…
Reference in New Issue
Block a user