Added curry to fix.py, converted some code to use it.

This commit is contained in:
Jeremy Fincher 2003-11-04 08:26:54 +00:00
parent c1e9205545
commit 93f02aa959
3 changed files with 6 additions and 3 deletions

View File

@ -36,11 +36,14 @@ Fixes stuff that Python should have but doesn't.
__all__ = []
exported = ['ignore', 'catch', 'reviter', 'window', 'group',
'partition', 'any', 'all', 'rsplit']
'partition', 'any', 'all', 'rsplit', 'curry']
import new
import string
string.ascii = string.maketrans('', '')
curry = new.instancemethod
def ignore(*args, **kwargs):
"""Simply ignore the arguments sent to it."""
pass

View File

@ -249,7 +249,7 @@ class IrcState(IrcCommandDispatcher):
self.nicksToHostmasks = ircutils.IrcDict()
def __getstate__(self):
return map(lambda name: getattr(self, name), self.__slots__)
return map(curry(getattr, self), self.__slots__)
def __setstate__(self, t):
for (name, value) in zip(self.__slots__, t):

View File

@ -235,7 +235,7 @@ def perlReToReplacer(s):
flags = filter('g'.__ne__, flags)
r = perlReToPythonRe('/'.join(('', regexp, flags)))
if g:
return lambda s: r.sub(replace, s)
return curry(r.sub, replace)
else:
return lambda s: r.sub(replace, s, 1)