1
2
3
4
5
6 import sys
7
8 from rdkit import six
9
10
12 """ base class for all virtual library nodes,
13 defines minimal required interface
14
15 """
16
18 self._children = []
19 self._parents = []
20
21
22
23
24
26 """ part of the iterator interface """
27 self.reset()
28 return self
29
31 """ part of the iterator interface
32
33 raises StopIteration on failure
34 """
35 pass
36
43
44
45
46
47
48
49
51 """
52
53 >>> p1 = VLibNode()
54 >>> p2 = VLibNode()
55 >>> c1 = VLibNode()
56 >>> p1.AddChild(c1)
57 >>> len(c1.GetParents())
58 1
59 >>> len(p1.GetChildren())
60 1
61 >>> p2.AddChild(c1,notify=0)
62 >>> len(c1.GetParents())
63 1
64 >>> len(p2.GetChildren())
65 1
66 >>> c1.AddParent(p2,notify=0)
67 >>> len(c1.GetParents())
68 2
69 >>> len(p2.GetChildren())
70 1
71
72 """
73 self._children.append(child)
74 if notify:
75 child.AddParent(self, notify=0)
76
78 """
79 >>> p1 = VLibNode()
80 >>> c1 = VLibNode()
81 >>> p1.AddChild(c1)
82 >>> len(c1.GetParents())
83 1
84 >>> len(p1.GetChildren())
85 1
86 >>> p1.RemoveChild(c1)
87 >>> len(c1.GetParents())
88 0
89 >>> len(p1.GetChildren())
90 0
91 """
92 self._children.remove(child)
93 if notify:
94 child.RemoveParent(self, notify=0)
95
97 return tuple(self._children)
98
100 """
101 >>> p1 = VLibNode()
102 >>> p2 = VLibNode()
103 >>> c1 = VLibNode()
104 >>> c1.AddParent(p1)
105 >>> len(c1.GetParents())
106 1
107 >>> len(p1.GetChildren())
108 1
109 >>> c1.AddParent(p2,notify=0)
110 >>> len(c1.GetParents())
111 2
112 >>> len(p2.GetChildren())
113 0
114 >>> p2.AddChild(c1,notify=0)
115 >>> len(c1.GetParents())
116 2
117 >>> len(p2.GetChildren())
118 1
119 """
120 self._parents.append(parent)
121 if notify:
122 parent.AddChild(self, notify=False)
123
125 """
126 >>> p1 = VLibNode()
127 >>> c1 = VLibNode()
128 >>> p1.AddChild(c1)
129 >>> len(c1.GetParents())
130 1
131 >>> len(p1.GetChildren())
132 1
133 >>> c1.RemoveParent(p1)
134 >>> len(c1.GetParents())
135 0
136 >>> len(p1.GetChildren())
137 0
138 """
139 self._parents.remove(parent)
140 if notify:
141 parent.RemoveChild(self, notify=False)
142
144 return tuple(self._parents)
145
146 - def Destroy(self, notify=True, propagateDown=False, propagateUp=False):
147 """
148 >>> p1 = VLibNode()
149 >>> p2 = VLibNode()
150 >>> c1 = VLibNode()
151 >>> c2 = VLibNode()
152 >>> p1.AddChild(c1)
153 >>> p2.AddChild(c1)
154 >>> p2.AddChild(c2)
155 >>> len(c1.GetParents())
156 2
157 >>> len(c2.GetParents())
158 1
159 >>> len(p1.GetChildren())
160 1
161 >>> len(p2.GetChildren())
162 2
163 >>> c1.Destroy(propagateUp=True)
164 >>> len(p2.GetChildren())
165 0
166 >>> len(c1.GetParents())
167 0
168 >>> len(c2.GetParents())
169 0
170
171 """
172 if hasattr(self, '_destroyed'):
173 return
174 self._destroyed = True
175
176 if notify:
177 for o in self.GetChildren():
178 o.RemoveParent(self, notify=False)
179 if propagateDown:
180 o.Destroy(notify=True, propagateDown=True, propagateUp=propagateUp)
181 for o in self.GetParents():
182 o.RemoveChild(self, notify=False)
183 if propagateUp:
184 o.Destroy(notify=True, propagateDown=propagateDown, propagateUp=True)
185 self._children = []
186 self._parents = []
187
188
189 if six.PY3:
190 VLibNode.__next__ = VLibNode.next
191
192
193
194
195
196
198 import doctest
199 failed, _ = doctest.testmod(optionflags=doctest.ELLIPSIS, verbose=verbose)
200 sys.exit(failed)
201
202
203 if __name__ == '__main__':
204 _runDoctests()
205