def __init__(self, stream, encoding):
        HtmlPrinter.__init__(self, stream, encoding)
        self._level = 0

        # indenting control variables
        self._isInline = [1]  # prevent newline before first element
        self._inNoIndent = [0]
        self._indentForbidden = 0
        self._indentEndTag = False
        return
    def __init__(self, stream, encoding):
        HtmlPrinter.__init__(self, stream, encoding)
        self._level = 0

        # indenting control variables
        self._isInline = [1]  # prevent newline before first element
        self._inNoIndent = [0]
        self._indentForbidden = 0
        self._indentEndTag = False
        return
    def comment(self, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.comment(self, data)
        return
    def processingInstruction(self, target, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.processingInstruction(self, target, data)
        return
    def comment(self, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.comment(self, data)
        return
    def processingInstruction(self, target, data):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # OK to indent end-tag
        self._indentEndTag = True

        # try to indent
        if not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))
        HtmlPrinter.processingInstruction(self, target, data)
        return
    def endElement(self, namespaceUri, tagName):
        # Undo changes to indenting rules for this element
        self._level -= 1
        inline = self._isInline.pop()

        if self._inElement:
            # An empty non-null namespace element (use XML short form)
            self.writeAscii('/>')
            self._inElement = False
        else:
            if not inline and not self._indentForbidden and self._indentEndTag:
                self.writeAscii('\n' + (self.indent * self._level))

            HtmlPrinter.endElement(self, namespaceUri, tagName)

        self._indentForbidden -= self._inNoIndent.pop()
        self._indentEndTag = not inline
        return
    def endElement(self, namespaceUri, tagName):
        # Undo changes to indenting rules for this element
        self._level -= 1
        inline = self._isInline.pop()

        if self._inElement:
            # An empty non-null namespace element (use XML short form)
            self.writeAscii('/>')
            self._inElement = False
        else:
            if not inline and not self._indentForbidden and self._indentEndTag:
                self.writeAscii('\n' + (self.indent * self._level))

            HtmlPrinter.endElement(self, namespaceUri, tagName)

        self._indentForbidden -= self._inNoIndent.pop()
        self._indentEndTag = not inline
        return
    def startElement(self, namespaceUri, tagName, namespaces, attributes):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # Create the lookup key for the various lookup tables
        key = (namespaceUri, tagName.lower())

        # Get the inline flag for this element
        inline = key in self.inlineElements

        if not inline and not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))

        HtmlPrinter.startElement(self, namespaceUri, tagName, namespaces,
                                 attributes)

        # Setup indenting rules for this element
        self._isInline.append(inline)
        self._inNoIndent.append(key in self.noIndentElements)
        self._indentForbidden += self._inNoIndent[-1]
        self._level += 1
        self._indentEndTag = False
        return
Beispiel #10
0
    def startElement(self, namespaceUri, tagName, namespaces, attributes):
        if self._inElement:
            self.writeAscii('>')
            self._inElement = False

        # Create the lookup key for the various lookup tables
        key = (namespaceUri, tagName.lower())

        # Get the inline flag for this element
        inline = key in self.inlineElements

        if not inline and not self._isInline[-1] and not self._indentForbidden:
            self.writeAscii('\n' + (self.indent * self._level))

        HtmlPrinter.startElement(self, namespaceUri, tagName, namespaces,
                                 attributes)

        # Setup indenting rules for this element
        self._isInline.append(inline)
        self._inNoIndent.append(key in self.noIndentElements)
        self._indentForbidden += self._inNoIndent[-1]
        self._level += 1
        self._indentEndTag = False
        return