6 from builtins
import range
8 """function for adding iterators to objects""" 9 if not hasattr(obj,
"__iter__"):
10 if hasattr(obj,
"size"):
11 obj.__iter__ = iteratorForSizedObjects
17 if not hasattr(obj,
"_begin")
and hasattr(obj,
"_end"):
20 obj.__iter__ = iteratorForBeginEnd
27 """dynamically added iterator""" 28 entries = container.size()
29 for entry
in range(entries):
34 """dynamically added iterator""" 36 while (it != self.end):
37 yield begin.__deref__()
43 raise cmserror(
"Automatic iterator search failed for %s. Either it is no iterable or it has multiple iterator possibilites. Please use loop(begin, end) instead." %obj )
48 objDict = obj.__dict__
49 _beginNames = [name
for name
in objDict.keys()
if "begin" in 51 _endNames = [name
for name
in objDict.keys()
if "end" in name.lower()]
52 if len(_beginNames)==1
and len(_endNames)== 1
and _beginNames[0].lower().
replace(
"begin",
"") == _endNames[0].lower().
replace(
"end",
""):
53 return objDict[_beginNames[0]], objDict[_endNames[0]]
60 if __name__ ==
"__main__":
82 self.assert_(hasattr(a,
"__iter__"))
89 self.assert_(b.__iter__())
def replace(string, replacements)
static const std::string B
def testFindIterators(self)
def iteratorForBeginEnd(self)
def iteratorForSizedObjects(self)
def testAddIterator(self)