def storeSectionState(self, level):
        """
        Takes a header tagname (e.g. 'h1') and adjusts the 
        stack that remembers the headers seen.
        """

        # self.document.append("<!-- storeSectionState(): " + str(len(self.header_stack)) + " open section tags. " + str(self.header_stack) + "-->\n")

        try:
            # special case.  we are not processing an OOo XML start tag which we
            # are going to insert <section> before.  we have reached a point
            # where all sections need to be closed. EG </office:body> or </text:section>,
            # both of which are hierarchical => scope closure for all open <section> tags
            bClosedAllSections = ( level == u'0' )
            if bClosedAllSections:
                # have reached a point where all sections need to be closed
                iSectionsClosed = len(self.header_stack)
                while len(self.header_stack) > 0:
                    del(self.header_stack[-1])
                return iSectionsClosed

            if len(self.header_stack) == 0:
                # no open section tags
                iSectionsClosed = 0
                self.header_stack.append(level)
            else:
                iLastLevel = self.header_stack[-1]
                if level > iLastLevel:
                    # open sections tags AND no sections need closing
                    iSectionsClosed = 0
                    self.header_stack.append(level)
                elif level == iLastLevel:
                    # open sections tags AND need to closed one of the sections
                    iSectionsClosed = 1
                    # imagine deleting the last level and then re-adding it
                elif level < iLastLevel:
                    # open sections tags AND need to closed some of the sections
                    del(self.header_stack[-1])
                    iSectionsClosed = 1
                    iSectionsClosed += self.storeSectionState(level)

            return iSectionsClosed

        except IndexError:
            print level
            raise
def storeSectionState ( self , level ) : try : bClosedAllSections = ( level == u'0' ) if bClosedAllSections : iSectionsClosed = len ( self . header_stack ) while len ( self . header_stack ) > 0 : del ( self . header_stack [ - 1 ] ) return iSectionsClosed if len ( self . header_stack ) == 0 : iSectionsClosed = 0 self . header_stack . append ( level ) else : iLastLevel = self . header_stack [ - 1 ] if level > iLastLevel : iSectionsClosed = 0 self . header_stack . append ( level ) elif level == iLastLevel : iSectionsClosed = 1 elif level < iLastLevel : del ( self . header_stack [ - 1 ] ) iSectionsClosed = 1 iSectionsClosed += self . storeSectionState ( level ) return iSectionsClosed except IndexError : print level raise
Takes a header tagname (e.g. 'h1') and adjusts the 
        stack that remembers the headers seen.