Browse Source

lxml 3.5 compatibility (Fix #282)

pull/290/head
Florian Mounier 9 years ago
parent
commit
46066e8eb4
  1. 6
      docs/changelog.rst
  2. 19
      pygal/svg.py

6
docs/changelog.rst

@ -2,6 +2,12 @@
Changelog
=========
2.0.11
======
* lxml 3.5 compatibility (#282)
2.0.10
======

19
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"<?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]
) + 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

Loading…
Cancel
Save