1
2
3
4
5
6 from rdkit import six
7 from rdkit.VLib.Node import VLibNode
8
9
11 """ base class for nodes which supply things
12
13 Assumptions:
14 1) no parents
15
16 Usage Example:
17 >>> supplier = SupplyNode(contents=[1,2,3])
18 >>> supplier.next()
19 1
20 >>> supplier.next()
21 2
22 >>> supplier.next()
23 3
24 >>> supplier.next()
25 Traceback (most recent call last):
26 ...
27 StopIteration
28 >>> supplier.reset()
29 >>> supplier.next()
30 1
31 >>> [x for x in supplier]
32 [1, 2, 3]
33
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
48
50 if self._pos == len(self._contents):
51 raise StopIteration
52
53 res = self._contents[self._pos]
54 self._pos += 1
55 return res
56
58 raise ValueError('SupplyNodes do not have parents')
59
60
61 if six.PY3:
62 SupplyNode.__next__ = SupplyNode.next
63
64
65
66
67
68
70 import sys
71 import doctest
72 failed, _ = doctest.testmod(optionflags=doctest.ELLIPSIS, verbose=verbose)
73 sys.exit(failed)
74
75
76 if __name__ == '__main__':
77 _runDoctests()
78