Next / Previous / Contents / Shipman's homepage

25. Sox.end()

sox.py
# - - -   S o x . e n d

    def end(self, elt):
        '''Write the closing tag for the top open element.
        '''

If elt is not the top of the element stack, the caller has failed to nest the calls properly.

sox.py
        #-- 1
        # [ if (self._stack is empty) or (self._stack[-1] is
        #   not elt) ->
        #     raise SoxError
        #   else ->
        #     self._stack  :=  self._stack[:-1] ]
        if len(self._stack) == 0:
            raise SoxError("Attempt to close a %s tag when all "
                "elements have already been closed." % elt.tag)
        elif self._stack[-1] is not elt:
            raise SoxError("Attempt to close a %s tag when it "
                "does not match the current open %s tag." %
                (elt.tag, self._stack[-1].tag))
        else:
            self._stack.pop()

The closing tag has the form “</tag”, but the tag name must be converted to ASCII.

sox.py
        #-- 2
        # [ self.outFile  +:=  a closing tag for name elt.tag ]
        self._endTag(elt.tag)