CMS 3D CMS Logo

Classes | Functions
python.iterators Namespace Reference

Classes

class  TestIterators
 

Functions

def _findIterators (obj)
 
def addIterator (obj)
 
def emptyIterator (self)
 
def iteratorForBeginEnd (self)
 
def iteratorForSizedObjects (self)
 

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 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 
58 
def replace(string, replacements)
def _findIterators(obj)
Definition: iterators.py:47
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 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 
25 
def addIterator(obj)
Definition: iterators.py:7
def _findIterators(obj)
Definition: iterators.py:47
def python.iterators.emptyIterator (   self)
empty iterator

Definition at line 41 of file iterators.py.

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 
46 # automatic detection of iterators.
def emptyIterator(self)
Definition: iterators.py:41
def python.iterators.iteratorForBeginEnd (   self)
dynamically added iterator

Definition at line 33 of file iterators.py.

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

Definition at line 26 of file iterators.py.

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