This function is recursive. It is initially called
to report on the first-level
children of the input document root, and at that
level it has a
depth of zero.
After processing the
section elements at
the current level, it calls itself recursively with a
depth increased by one per level.
# - - - r e p o r t S e c t i o n s def reportSections(flow, depth, node): '''Recursively generate section lines in the report. [ (flow is an et.Element) and (depth is a nonnegative integer) and (node is an et.Element) -> flow +:= blocks describing section element descendants of inDoc.root, starting at indent level (depth) ] ''' #-- 1 # [ sectionList := list of all section element children of node ] sectionList = node.xpath("section|sect1|sect2|sect3|sect4") #-- 2 # [ flow +:= blocks describing elements of sectionList, # with recursively nested child blocks for descendant # sections of members of sectionList ] for sectNode in sectionList: #-- 2 body # [ sectNode is an et.Element -> # flow +:= a block describing sectNode, with # recursively nested child blocks for descendant # sections of sectNode ]
#-- 2.1 # [ flow +:= a block describing sectNode, indented # by depth ] reportLine(flow, depth, sectNode) #-- 2.2 # [ flow +:= blocks describing section element # descendants of sectNode, starting at indent # level (depth+1) ] reportSections(flow, depth+1, sectNode)