CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 46 of file iterators.py.

References python.rootplot.root2matplotlib.replace().

Referenced by python.iterators.addIterator().

46 
47 def _findIterators(obj):
48  objDict = obj.__dict__
49  _beginNames = [name for name in objDict.keys() if "begin" in
50 name.lower()]
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]]
54  else:
55  return False
56 
57 
def python.iterators.addIterator (   obj)
function for adding iterators to objects

Definition at line 6 of file iterators.py.

References python.iterators._findIterators().

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

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

Definition at line 40 of file iterators.py.

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

Definition at line 32 of file iterators.py.

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

Definition at line 25 of file iterators.py.

25 
26 def iteratorForSizedObjects(self):
27  """dynamically added iterator"""
28  entries = container.size()
29  for entry in xrange(entries):
30  yield obj[entry]
31 
def iteratorForSizedObjects
Definition: iterators.py:25