Revision 403f5172 lib/compat.py

b/lib/compat.py
55 55
  sha1_hash = sha.new
56 56

  
57 57

  
58
def all(seq, pred=bool): # pylint: disable-msg=W0622
59
  """Returns True if pred(x) is True for every element in the iterable.
60

  
61
  Please note that this function provides a C{pred} parameter which isn't
62
  available in the version included in Python 2.5 and above.
58
def _all(seq):
59
  """Returns True if all elements in the iterable are True.
63 60

  
64 61
  """
65
  for _ in itertools.ifilterfalse(pred, seq):
62
  for _ in itertools.ifilterfalse(bool, seq):
66 63
    return False
67 64
  return True
68 65

  
69

  
70
def any(seq, pred=bool): # pylint: disable-msg=W0622
71
  """Returns True if pred(x) is True for at least one element in the iterable.
72

  
73
  Please note that this function provides a C{pred} parameter which isn't
74
  available in the version included in Python 2.5 and above.
66
def _any(seq):
67
  """Returns True if any element of the iterable are True.
75 68

  
76 69
  """
77
  for _ in itertools.ifilter(pred, seq):
70
  for _ in itertools.ifilter(bool, seq):
78 71
    return True
79 72
  return False
80 73

  
74
try:
75
  all = all # pylint: disable-msg=W0622
76
except NameError:
77
  all = _all
78

  
79
try:
80
  any = any # pylint: disable-msg=W0622
81
except NameError:
82
  any = _any
81 83

  
82 84
def partition(seq, pred=bool): # pylint: disable-msg=W0622
83 85
  """Partition a list in two, based on the given predicate.
......
106 108
  return newfunc
107 109

  
108 110

  
111
if functools is None:
112
  partial = _partial
113
else:
114
  partial = functools.partial
115

  
116

  
109 117
def TryToRoman(val, convert=True):
110 118
  """Try to convert a value to roman numerals
111 119

  
......
128 136
  else:
129 137
    return val
130 138

  
131

  
132
if functools is None:
133
  partial = _partial
134
else:
135
  partial = functools.partial

Also available in: Unified diff