Beispiel #1
0
    def __init__(self, stream=sys.stdout, encoding='utf-8', printer=None, ns_hints=None, is_html=False,
                 indent=False, canonical=False, added_attributes=None,
                 removed_ns_decls=None):
        """
        Initializes an instance of the class, selecting the appropriate
        printer to use, depending on the isHtml and indent flags.
        ns_hints, if given, is a dictionary of namespace mappings that
        help determine if namespace declarations need to be emitted when
        visiting the first Element node.
        """
        if printer:
            self.printer = printer
        elif indent and is_html:
            self.printer = _htmlprinters.htmlprettyprinter(stream, encoding)
        elif indent:
            self.printer = _xmlprinters.xmlprettyprinter(stream, encoding)
        elif is_html:
            self.printer = _htmlprinters.htmlprinter(stream, encoding)
        elif canonical:
            self.printer = _xmlprinters.CanonicalXmlPrinter(stream, encoding)
        else:
            self.printer = _xmlprinters.xmlprinter(stream, encoding)

        # Namespaces
        self._namespaces = [{'xml' : XML_NAMESPACE}]
        self._ns_hints = ns_hints
        self._added_attributes = added_attributes or {}
        self._removed_ns_decls = removed_ns_decls or []
        return
Beispiel #2
0
def get_printer(stream,
                encoding='utf-8',
                ns_hints=None,
                is_html=False,
                indent=False,
                canonical=False,
                added_attributes=None,
                removed_ns_decls=None):
    """
    Initializes an instance of the class, selecting the appropriate
    printer to use, depending on the isHtml and indent flags.
    ns_hints, if given, is a dictionary of namespace mappings that
    help determine if namespace declarations need to be emitted when
    visiting the first Element node.
    """
    if indent and is_html:
        printer = _htmlprinters.htmlprettyprinter(stream, encoding)
    elif indent:
        printer = _xmlprinters.xmlprettyprinter(stream, encoding)
    elif is_html:
        printer = _htmlprinters.htmlprinter(stream, encoding)
    elif canonical:
        printer = _xmlprinters.CanonicalXmlPrinter(stream, encoding)
    else:
        printer = _xmlprinters.xmlprinter(stream, encoding)
    return printer
Beispiel #3
0
def get_printer(stream, encoding='utf-8', ns_hints=None, is_html=False,
             indent=False, canonical=False, added_attributes=None,
             removed_ns_decls=None):
    """
    Initializes an instance of the class, selecting the appropriate
    printer to use, depending on the isHtml and indent flags.
    ns_hints, if given, is a dictionary of namespace mappings that
    help determine if namespace declarations need to be emitted when
    visiting the first Element node.
    """
    if indent and is_html:
        printer = _htmlprinters.htmlprettyprinter(stream, encoding)
    elif indent:
        printer = _xmlprinters.xmlprettyprinter(stream, encoding)
    elif is_html:
        printer = _htmlprinters.htmlprinter(stream, encoding)
    elif canonical:
        printer = _xmlprinters.CanonicalXmlPrinter(stream, encoding)
    else:
        printer = _xmlprinters.xmlprinter(stream, encoding)
    return printer
Beispiel #4
0
    def __init__(self,
                 stream=sys.stdout,
                 encoding='utf-8',
                 printer=None,
                 ns_hints=None,
                 is_html=False,
                 indent=False,
                 canonical=False,
                 added_attributes=None,
                 removed_ns_decls=None):
        """
        Initializes an instance of the class, selecting the appropriate
        printer to use, depending on the isHtml and indent flags.
        ns_hints, if given, is a dictionary of namespace mappings that
        help determine if namespace declarations need to be emitted when
        visiting the first Element node.
        """
        if printer:
            self.printer = printer
        elif indent and is_html:
            self.printer = _htmlprinters.htmlprettyprinter(stream, encoding)
        elif indent:
            self.printer = _xmlprinters.xmlprettyprinter(stream, encoding)
        elif is_html:
            self.printer = _htmlprinters.htmlprinter(stream, encoding)
        elif canonical:
            self.printer = _xmlprinters.CanonicalXmlPrinter(stream, encoding)
        else:
            self.printer = _xmlprinters.xmlprinter(stream, encoding)

        # Namespaces
        self._namespaces = [{'xml': XML_NAMESPACE}]
        self._ns_hints = ns_hints
        self._added_attributes = added_attributes or {}
        self._removed_ns_decls = removed_ns_decls or []
        return