Example #1
0
File: svg.py Project: sattel/pygal
    def render(self, is_unicode=False, pretty_print=False):
        """Last thing to do before rendering"""
        for f in self.graph.xml_filters:
            self.root = f(self.root)
        args = {
            'encoding': 'utf-8'
        }

        svg = b''
        if etree.lxml:
            args['pretty_print'] = pretty_print

        if not self.graph.disable_xml_declaration:
            svg = b"<?xml version='1.0' encoding='utf-8'?>\n"

        if not self.graph.disable_xml_declaration:
            svg += b'\n'.join(
                [etree.tostring(
                    pi, **args)
                 for pi in self.processing_instructions]
            )

        svg += etree.tostring(
            self.root, **args)

        if self.graph.disable_xml_declaration or is_unicode:
            svg = svg.decode('utf-8')
        return svg
Example #2
0
    def render(self, is_unicode=False, pretty_print=False):
        """Last thing to do before rendering"""
        for f in self.graph.xml_filters:
            self.root = f(self.root)
        args = {
            'encoding': 'utf-8'
        }
        svg = b''
        if etree.lxml:
            args['pretty_print'] = pretty_print
            args['xml_declaration'] = not self.graph.disable_xml_declaration
        else:
            if not self.graph.disable_xml_declaration:
                svg = b"<?xml version='1.0' encoding='utf-8'?>\n"
        svg += etree.tostring(
            self.root, **args)

        if 'xml_declaration' in args:
            args.pop('xml_declaration')

        if not self.graph.disable_xml_declaration:
            svg = b'\n'.join(
                [etree.tostring(
                    pi, **args)
                 for pi in self.processing_instructions] + [svg]
            )
        if self.graph.disable_xml_declaration or is_unicode:
            svg = svg.decode('utf-8')
        return svg
Example #3
0
 def render(self, is_unicode=False, pretty_print=False):
     """Last thing to do before rendering"""
     for f in self.graph.xml_filters:
         self.root = f(self.root)
     args = {"encoding": "utf-8"}
     if etree.lxml:
         args["pretty_print"] = pretty_print
     svg = etree.tostring(self.root, **args)
     if not self.graph.disable_xml_declaration:
         svg = b"\n".join([etree.tostring(pi, **args) for pi in self.processing_instructions]) + b"\n" + svg
     if self.graph.disable_xml_declaration or is_unicode:
         svg = svg.decode("utf-8")
     return svg