MCPcopy Create free account
hub / github.com/ActiveState/code / add

Method add

recipes/Python/576966_DnTree/recipe-576966.py:127–162  ·  view source on GitHub ↗

Add node to tree. dn --- distinguished name of node.

(self, dn)

Source from the content-addressed store, hash-verified

125 return dn[:_len]
126
127 def add(self, dn):
128 """Add node to tree.
129
130 dn --- distinguished name of node.
131 """
132
133 if dn in self.dn_set:
134 raise ValueError('A record with dn=%s already exists!' % dn)
135
136 parent_dn = self.get_parent_dn(dn)
137 fake_parent = self.get_fake_parent_dn(dn)
138
139 if parent_dn != fake_parent:
140 try:
141 self.fake_parent[fake_parent].append(dn)
142 except KeyError:
143 self.fake_parent[fake_parent] = [dn]
144
145 self.parent[dn] = parent_dn
146 try:
147 self.childs[parent_dn].append(dn)
148 except KeyError:
149 self.childs[parent_dn] = [dn]
150
151 try:
152 for i in self.fake_parent.pop(dn):
153 self.childs[""].remove(i)
154 self.parent[i] = dn
155 try:
156 self.childs[dn].append(i)
157 except KeyError:
158 self.childs[dn] = [i]
159 except KeyError:
160 pass
161
162 self.dn_set.add(dn)
163
164 def rename(self, old_dn, new_dn):
165 """Rename node.

Callers 11

__init__Method · 0.95
renameMethod · 0.95
add_vertexMethod · 0.45
find_rootsMethod · 0.45
__init__Method · 0.45
create_expressionFunction · 0.45
min_cut_phaseFunction · 0.45
itersubclassesFunction · 0.45
DFSFunction · 0.45
__setitem__Method · 0.45
__init__Method · 0.45

Calls 5

get_parent_dnMethod · 0.95
get_fake_parent_dnMethod · 0.95
appendMethod · 0.45
popMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected