7 """function for adding iterators to objects"""
8 if not hasattr(obj,
"__iter__"):
9 if hasattr(obj,
"size"):
10 obj.__iter__ = iteratorForSizedObjects
16 if not hasattr(obj,
"_begin")
and hasattr(obj,
"_end"):
19 obj.__iter__ = iteratorForBeginEnd
26 """dynamically added iterator"""
27 entries = container.size()
28 for entry
in xrange(entries):
33 """dynamically added iterator"""
35 while (it != self.end):
36 yield begin.__deref__()
42 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 )
47 objDict = obj.__dict__
48 _beginNames = [name
for name
in objDict.keys()
if "begin" in
50 _endNames = [name
for name
in objDict.keys()
if "end" in name.lower()]
51 if len(_beginNames)==1
and len(_endNames)== 1
and _beginNames[0].lower().
replace(
"begin",
"") == _endNames[0].lower().
replace(
"end",
""):
52 return objDict[_beginNames[0]], objDict[_endNames[0]]
59 if __name__ ==
"__main__":
81 self.assert_(hasattr(a,
"__iter__"))
88 self.assert_(b.__iter__())
def iteratorForSizedObjects