1
2
3
4
5
6 import sys
7 from rdkit import six
8
9 from rdkit.VLib.Node import VLibNode
10
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
49 if self._pos == len(self._contents):
50 raise StopIteration
51
52 res=self._contents[self._pos]
53 self._pos += 1
54 return res
56 raise ValueError('SupplyNodes do not have parents')
57
58 if six.PY3:
59 SupplyNode.__next__ = SupplyNode.next
60
61
62
63
64
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