Package SCons :: Package compat :: Module _scons_itertools
[hide private]
[frames] | no frames]

Source Code for Module SCons.compat._scons_itertools

  1  # 
  2  # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation 
  3  # 
  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: 
 11  # 
 12  # The above copyright notice and this permission notice shall be included 
 13  # in all copies or substantial portions of the Software. 
 14  # 
 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. 
 22  # 
 23   
 24  __revision__ = "src/engine/SCons/compat/_scons_itertools.py 5110 2010/07/25 16:14:38 bdeegan" 
 25   
 26  __doc__ = """ 
 27  Implementations of itertools functions for Python versions that don't 
 28  have iterators. 
 29   
 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. 
 35   
 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). 
 43   
 44  Note that these do not have independent unit tests, so it's possible 
 45  that there are bugs. 
 46  """ 
 47   
48 -def chain(*iterables):
49 result = [] 50 for x in iterables: 51 result.extend(list(x)) 52 return result
53
54 -def count(n=0):
55 # returns infinite length, should not be supported 56 raise NotImplementedError
57
58 -def cycle(iterable):
59 # returns infinite length, should not be supported 60 raise NotImplementedError
61
62 -def dropwhile(predicate, iterable):
63 result = [] 64 for x in iterable: 65 if not predicate(x): 66 result.append(x) 67 break 68 result.extend(iterable) 69 return result
70
71 -def groupby(iterable, *args):
72 raise NotImplementedError
73
74 -def ifilter(predicate, iterable):
75 result = [] 76 if predicate is None: 77 predicate = bool 78 for x in iterable: 79 if predicate(x): 80 result.append(x) 81 return result
82
83 -def ifilterfalse(predicate, iterable):
84 result = [] 85 if predicate is None: 86 predicate = bool 87 for x in iterable: 88 if not predicate(x): 89 result.append(x) 90 return result
91
92 -def imap(function, *iterables):
93 return apply(map, (function,) + tuple(iterables))
94
95 -def islice(*args, **kw):
96 raise NotImplementedError
97
98 -def izip(*iterables):
99 return apply(zip, iterables)
100
101 -def repeat(*args, **kw):
102 # returns infinite length, should not be supported 103 raise NotImplementedError
104
105 -def starmap(*args, **kw):
106 raise NotImplementedError
107
108 -def takewhile(predicate, iterable):
109 result = [] 110 for x in iterable: 111 if predicate(x): 112 result.append(x) 113 else: 114 break 115 return result
116
117 -def tee(*args, **kw):
118 raise NotImplementedError
119 120 # Local Variables: 121 # tab-width:4 122 # indent-tabs-mode:nil 123 # End: 124 # vim: set expandtab tabstop=4 shiftwidth=4: 125