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 46 of file iterators.py.

References python.rootplot.root2matplotlib.replace().

Referenced by python.iterators.addIterator().

46 def _findIterators(obj):
47  objDict = obj.__dict__
48  _beginNames = [name for name in objDict.keys() if "begin" in
49 name.lower()]
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]]
53  else:
54  return False
55 
56 
57 
def replace(string, replacements)
def _findIterators(obj)
Definition: iterators.py:46
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 def addIterator(obj):
7  """function for adding iterators to objects"""
8  if not hasattr(obj, "__iter__"):
9  if hasattr(obj, "size"):
10  obj.__iter__ = iteratorForSizedObjects
11  else:
12  try:
13  begin, end = _findIterators(obj)
14  except:
15  return obj
16  if not hasattr(obj, "_begin") and hasattr(obj, "_end"):
17  obj._begin = begin
18  obj._end = end
19  obj.__iter__ = iteratorForBeginEnd
20  #else:
21  # obj.__iter__ = EmptyIterator
22  return obj
23 
24 
def addIterator(obj)
Definition: iterators.py:6
def _findIterators(obj)
Definition: iterators.py:46
def python.iterators.emptyIterator (   self)
empty iterator

Definition at line 40 of file iterators.py.

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

Definition at line 32 of file iterators.py.

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

Definition at line 25 of file iterators.py.

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