From 46066e8eb4141e46e6bcf161710d2dd0f34a562c Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Mon, 16 Nov 2015 10:50:54 +0100 Subject: [PATCH] lxml 3.5 compatibility (Fix #282) --- docs/changelog.rst | 6 ++++++ pygal/svg.py | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index fdd0e70..8dcc69f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,12 @@ Changelog ========= +2.0.11 +====== + +* lxml 3.5 compatibility (#282) + + 2.0.10 ====== diff --git a/pygal/svg.py b/pygal/svg.py index 1d1108e..8608a79 100644 --- a/pygal/svg.py +++ b/pygal/svg.py @@ -46,9 +46,7 @@ class Svg(object): self.id = '#chart-%s ' % graph.uuid else: self.id = '' - self.processing_instructions = [ - etree.ProcessingInstruction( - u('xml'), u("version='1.0' encoding='utf-8'"))] + self.processing_instructions = [] if etree.lxml: attrs = { 'nsmap': { @@ -323,16 +321,25 @@ class Svg(object): args = { 'encoding': 'utf-8' } + svg = b'' if etree.lxml: args['pretty_print'] = pretty_print - svg = etree.tostring( + args['xml_declaration'] = not self.graph.disable_xml_declaration + else: + if not self.graph.disable_xml_declaration: + svg = b"\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] - ) + b'\n' + svg + for pi in self.processing_instructions] + [svg] + ) if self.graph.disable_xml_declaration or is_unicode: svg = svg.decode('utf-8') return svg