mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05: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',
|
self._values = ['actions', 'chars', 'frowns', 'joins', 'kicks','modes',
|
||||||
'msgs', 'parts', 'quits', 'smileys', 'topics', 'words']
|
'msgs', 'parts', 'quits', 'smileys', 'topics', 'words']
|
||||||
def values(self):
|
def values(self):
|
||||||
return map(curry(getattr, self), self._values)
|
return map(utils.curry(getattr, self), self._values)
|
||||||
|
|
||||||
def addMsg(self, msg):
|
def addMsg(self, msg):
|
||||||
self.msgs += 1
|
self.msgs += 1
|
||||||
|
21
src/fix.py
21
src/fix.py
@ -39,8 +39,8 @@ __revision__ = "$Id$"
|
|||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
exported = ['ignore', 'catch', 'reviter', 'window', 'group',
|
exported = ['ignore', 'reviter', 'window', 'group', 'sorted',
|
||||||
'partition', 'any', 'all', 'rsplit', 'curry']
|
'partition', 'any', 'all', 'rsplit']
|
||||||
|
|
||||||
import new
|
import new
|
||||||
import string
|
import string
|
||||||
@ -61,19 +61,10 @@ def choice(iterable):
|
|||||||
return ret
|
return ret
|
||||||
random.choice = choice
|
random.choice = choice
|
||||||
|
|
||||||
curry = new.instancemethod
|
|
||||||
|
|
||||||
def ignore(*args, **kwargs):
|
def ignore(*args, **kwargs):
|
||||||
"""Simply ignore the arguments sent to it."""
|
"""Simply ignore the arguments sent to it."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def catch(f, *args, **kwargs):
|
|
||||||
"""Catches all exceptions raises by f."""
|
|
||||||
try:
|
|
||||||
return f(*args, **kwargs)
|
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def reviter(L):
|
def reviter(L):
|
||||||
"""Iterates through a list in reverse."""
|
"""Iterates through a list in reverse."""
|
||||||
for i in xrange(len(L) - 1, -1, -1):
|
for i in xrange(len(L) - 1, -1, -1):
|
||||||
@ -177,6 +168,14 @@ def rsplit(s, sep=None, maxsplit=-1):
|
|||||||
L.reverse()
|
L.reverse()
|
||||||
return [s[::-1] for s in L]
|
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
|
import operator
|
||||||
def itemgetter(i):
|
def itemgetter(i):
|
||||||
return lambda x: x[i]
|
return lambda x: x[i]
|
||||||
|
@ -279,7 +279,7 @@ class IrcState(IrcCommandDispatcher):
|
|||||||
self.nicksToHostmasks = ircutils.IrcDict()
|
self.nicksToHostmasks = ircutils.IrcDict()
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
return map(curry(getattr, self), self.__slots__)
|
return map(utils.curry(getattr, self), self.__slots__)
|
||||||
|
|
||||||
def __setstate__(self, t):
|
def __setstate__(self, t):
|
||||||
for (name, value) in zip(self.__slots__, t):
|
for (name, value) in zip(self.__slots__, t):
|
||||||
|
@ -53,6 +53,8 @@ from itertools import imap, ifilter
|
|||||||
|
|
||||||
from structures import TwoWayDictionary
|
from structures import TwoWayDictionary
|
||||||
|
|
||||||
|
curry = new.instancemethod
|
||||||
|
|
||||||
def normalizeWhitespace(s):
|
def normalizeWhitespace(s):
|
||||||
"""Normalizes the whitespace in a string; \s+ becomes one space."""
|
"""Normalizes the whitespace in a string; \s+ becomes one space."""
|
||||||
return ' '.join(s.split())
|
return ' '.join(s.split())
|
||||||
@ -619,7 +621,6 @@ class InsensitivePreservingDict(UserDict.DictMixin, object):
|
|||||||
def __reduce__(self):
|
def __reduce__(self):
|
||||||
return (self.__class__, (dict(self.data.values()),))
|
return (self.__class__, (dict(self.data.values()),))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys, doctest
|
import sys, doctest
|
||||||
doctest.testmod(sys.modules['__main__'])
|
doctest.testmod(sys.modules['__main__'])
|
||||||
|
Loading…
Reference in New Issue
Block a user