Package rdkit :: Package VLib :: Module Supply
[hide private]
[frames] | no frames]

Source Code for Module rdkit.VLib.Supply

 1  #  $Id$ 
 2  # 
 3  #  Copyright (C) 2003 Rational Discovery LLC 
 4  #     All Rights Reserved 
 5  # 
 6  import sys 
 7  from rdkit import six 
 8   
 9  from rdkit.VLib.Node import VLibNode 
10   
11 -class SupplyNode(VLibNode):
12 """ base class for nodes which supply things 13 14 Assumptions: 15 1) no parents 16 17 Usage Example: 18 >>> supplier = SupplyNode(contents=[1,2,3]) 19 >>> supplier.next() 20 1 21 >>> supplier.next() 22 2 23 >>> supplier.next() 24 3 25 >>> supplier.next() 26 Traceback (most recent call last): 27 ... 28 StopIteration 29 >>> supplier.reset() 30 >>> supplier.next() 31 1 32 >>> [x for x in supplier] 33 [1, 2, 3] 34 35 36 """
37 - def __init__(self,contents=None,**kwargs):
38 VLibNode.__init__(self,**kwargs) 39 if contents is not None: 40 self._contents = contents 41 else: 42 self._contents = [] 43 self._pos = 0
44
45 - def reset(self):
46 VLibNode.reset(self) 47 self._pos = 0
48 - def next(self):
49 if self._pos == len(self._contents): 50 raise StopIteration 51 52 res=self._contents[self._pos] 53 self._pos += 1 54 return res
55 - def AddParent(self,parent,notify=1):
56 raise ValueError('SupplyNodes do not have parents')
57 58 if six.PY3: 59 SupplyNode.__next__ = SupplyNode.next 60 61 #------------------------------------ 62 # 63 # doctest boilerplate 64 #
65 -def _test():
66 import doctest,sys 67 return doctest.testmod(sys.modules["__main__"])
68 69 if __name__ == '__main__': 70 import sys 71 failed,tried = _test() 72 sys.exit(failed) 73