def _collapse_subtree(self, name, recursive=True):
oname = name<EOL>children = self._db[name]["<STR_LIT>"]<EOL>data = self._db[name]["<STR_LIT:data>"]<EOL>del_list = []<EOL>while (len(children) == <NUM_LIT:1>) and (not data):<EOL><INDENT>del_list.append(name)<EOL>name = children[<NUM_LIT:0>]<EOL>children = self._db[name]["<STR_LIT>"]<EOL>data = self._db[name]["<STR_LIT:data>"]<EOL><DEDENT>parent = self._db[oname]["<STR_LIT>"]<EOL>self._db[name]["<STR_LIT>"] = parent<EOL>if parent:<EOL><INDENT>self._db[parent]["<STR_LIT>"].remove(oname)<EOL>self._db[parent]["<STR_LIT>"] = sorted(self._db[parent]["<STR_LIT>"] + [name])<EOL><DEDENT>else:<EOL><INDENT>self._root = name<EOL>self._root_hierarchy_length = len(<EOL>self.root_name.split(self._node_separator)<EOL>)<EOL><DEDENT>for node in del_list:<EOL><INDENT>self._del_node(node)<EOL><DEDENT>if recursive:<EOL><INDENT>for child in copy.copy(children):<EOL><INDENT>self._collapse_subtree(child)<EOL><DEDENT><DEDENT>
Collapse a sub-tree.