CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions
python.iterators Namespace Reference

Classes

class  TestIterators
 

Functions

def _findIterators
 
def addIterator
 
def emptyIterator
 
def iteratorForBeginEnd
 
def iteratorForSizedObjects
 

Function Documentation

def python.iterators._findIterators (   obj)
private

Definition at line 47 of file iterators.py.

References python.rootplot.root2matplotlib.replace().

Referenced by python.iterators.addIterator().

47 
48 def _findIterators(obj):
49  objDict = obj.__dict__
50  _beginNames = [name for name in objDict.keys() if "begin" in
51 name.lower()]
52  _endNames = [name for name in objDict.keys() if "end" in name.lower()]
53  if len(_beginNames)==1 and len(_endNames)== 1 and _beginNames[0].lower().replace("begin","") == _endNames[0].lower().replace("end",""):
54  return objDict[_beginNames[0]], objDict[_endNames[0]]
55  else:
56  return False
57 
58 
def python.iterators.addIterator (   obj)
function for adding iterators to objects

Definition at line 7 of file iterators.py.

References python.iterators._findIterators().

Referenced by python.iterators.TestIterators.testAddIterator().

7 
8 def addIterator(obj):
9  """function for adding iterators to objects"""
10  if not hasattr(obj, "__iter__"):
11  if hasattr(obj, "size"):
12  obj.__iter__ = iteratorForSizedObjects
13  else:
14  try:
15  begin, end = _findIterators(obj)
16  except:
17  return obj
18  if not hasattr(obj, "_begin") and hasattr(obj, "_end"):
19  obj._begin = begin
20  obj._end = end
21  obj.__iter__ = iteratorForBeginEnd
22  #else:
23  # obj.__iter__ = EmptyIterator
24  return obj
25 
def python.iterators.emptyIterator (   self)
empty iterator

Definition at line 41 of file iterators.py.

41 
42 def emptyIterator(self):
43  """empty iterator"""
44  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 )
45 
46 
# automatic detection of iterators.
def python.iterators.iteratorForBeginEnd (   self)
dynamically added iterator

Definition at line 33 of file iterators.py.

33 
34 def iteratorForBeginEnd(self):
35  """dynamically added iterator"""
36  it = self._begin
37  while (it != self.end):
38  yield begin.__deref__() #*b
39  begin.__preinc__() #++b
40 
def iteratorForBeginEnd
Definition: iterators.py:33
def python.iterators.iteratorForSizedObjects (   self)
dynamically added iterator

Definition at line 26 of file iterators.py.

References sistrip::SpyUtilities.range().

26 
27 def iteratorForSizedObjects(self):
28  """dynamically added iterator"""
29  entries = container.size()
30  for entry in range(entries):
31  yield obj[entry]
32 
def iteratorForSizedObjects
Definition: iterators.py:26
const uint16_t range(const Frame &aFrame)