2
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
4
# Permission is hereby granted, free of charge, to any person obtaining
5
# a copy of this software and associated documentation files (the
6
# "Software"), to deal in the Software without restriction, including
7
# without limitation the rights to use, copy, modify, merge, publish,
8
# distribute, sublicense, and/or sell copies of the Software, and to
9
# permit persons to whom the Software is furnished to do so, subject to
10
# the following conditions:
12
# The above copyright notice and this permission notice shall be included
13
# in all copies or substantial portions of the Software.
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
__revision__ = "src/engine/SCons/compat/_scons_itertools.py 3842 2008/12/20 22:59:52 scons"
27
Implementations of itertools functions for Python versions that don't
30
These implement the functions by creating the entire list, not returning
31
it element-by-element as the real itertools functions do. This means
32
that early Python versions won't get the performance benefit of using
33
the itertools, but we can still use them so the later Python versions
34
do get the advantages of using iterators.
36
Because we return the entire list, we intentionally do not implement the
37
itertools functions that "return" infinitely-long lists: the count(),
38
cycle() and repeat() functions. Other functions below have remained
39
unimplemented simply because they aren't being used (yet) and it wasn't
40
obvious how to do it. Or, conversely, we only implemented those functions
41
that *were* easy to implement (mostly because the Python documentation
42
contained examples of equivalent code).
44
Note that these do not have independent unit tests, so it's possible
48
def chain(*iterables):
51
result.extend(list(x))
55
# returns infinite length, should not be supported
56
raise NotImplementedError
59
# returns infinite length, should not be supported
60
raise NotImplementedError
62
def dropwhile(predicate, iterable):
68
result.extend(iterable)
71
def groupby(iterable, *args):
72
raise NotImplementedError
74
def ifilter(predicate, iterable):
83
def ifilterfalse(predicate, iterable):
92
def imap(function, *iterables):
93
return apply(map, (function,) + tuple(iterables))
95
def islice(*args, **kw):
96
raise NotImplementedError
99
return apply(zip, iterables)
101
def repeat(*args, **kw):
102
# returns infinite length, should not be supported
103
raise NotImplementedError
105
def starmap(*args, **kw):
106
raise NotImplementedError
108
def takewhile(predicate, iterable):
117
def tee(*args, **kw):
118
raise NotImplementedError