def dfs(node):
    children = node.children
    if children:
        ret = []
        for name in sorted(six.iterkeys(children)):
            child = children[name]
            child_ret = dfs(child)
            if child_ret:
                ret.append((name, child_ret))
        if ret:
            return ret
    data = node.data
    if data:
        return data.to_dict()
def dfs(node):
    children = node.children
    if children:
        ret = []
        for name in sorted(six.iterkeys(children)):
            child = children[name]
            child_ret = dfs(child)
            if child_ret:
                ret.append((name, child_ret))
        if ret:
            return ret
    data = node.data
    if data:
        return data.to_dict()