mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-20 09:04:36 +01:00
Updated for 2.4.
This commit is contained in:
parent
1e0b039ff4
commit
40a2e07956
21
src/fix.py
21
src/fix.py
@ -37,8 +37,7 @@ __revision__ = "$Id$"
|
|||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
exported = ['ignore', 'reversed', 'window', 'group',
|
exported = ['ignore', 'window', 'group', 'partition', 'any', 'all', 'rsplit']
|
||||||
'partition', 'any', 'all', 'rsplit']
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import new
|
import new
|
||||||
@ -68,10 +67,12 @@ def ignore(*args, **kwargs):
|
|||||||
"""Simply ignore the arguments sent to it."""
|
"""Simply ignore the arguments sent to it."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def reversed(L):
|
if sys.version_info < (2, 4, 0):
|
||||||
|
def reversed(L):
|
||||||
"""Iterates through a sequence in reverse."""
|
"""Iterates through a sequence in reverse."""
|
||||||
for i in xrange(len(L) - 1, -1, -1):
|
for i in xrange(len(L) - 1, -1, -1):
|
||||||
yield L[i]
|
yield L[i]
|
||||||
|
exported.append('reversed')
|
||||||
|
|
||||||
def window(L, size):
|
def window(L, size):
|
||||||
"""Returns a sliding 'window' through the list L of size size."""
|
"""Returns a sliding 'window' through the list L of size size."""
|
||||||
@ -166,20 +167,24 @@ def all(p, seq):
|
|||||||
|
|
||||||
def rsplit(s, sep=None, maxsplit=-1):
|
def rsplit(s, sep=None, maxsplit=-1):
|
||||||
"""Equivalent to str.split, except splitting from the right."""
|
"""Equivalent to str.split, except splitting from the right."""
|
||||||
|
if sys.version_info < (2, 4, 0):
|
||||||
if sep is not None:
|
if sep is not None:
|
||||||
sep = sep[::-1]
|
sep = sep[::-1]
|
||||||
L = s[::-1].split(sep, maxsplit)
|
L = s[::-1].split(sep, maxsplit)
|
||||||
L.reverse()
|
L.reverse()
|
||||||
return [s[::-1] for s in L]
|
return [s[::-1] for s in L]
|
||||||
|
else:
|
||||||
|
return s.rsplit(sep, maxsplit)
|
||||||
|
|
||||||
import operator
|
if sys.version_info < (2, 4, 0):
|
||||||
def itemgetter(i):
|
import operator
|
||||||
|
def itemgetter(i):
|
||||||
return lambda x: x[i]
|
return lambda x: x[i]
|
||||||
|
|
||||||
def attrgetter(attr):
|
def attrgetter(attr):
|
||||||
return lambda x: getattr(x, attr)
|
return lambda x: getattr(x, attr)
|
||||||
operator.itemgetter = itemgetter
|
operator.itemgetter = itemgetter
|
||||||
operator.attrgetter = attrgetter
|
operator.attrgetter = attrgetter
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
import cStringIO as StringIO
|
import cStringIO as StringIO
|
||||||
|
Loading…
Reference in New Issue
Block a user