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 Changelog
========= =========
2.0.11
======
* lxml 3.5 compatibility (#282)
2.0.10 2.0.10
====== ======

19
pygal/svg.py

@ -46,9 +46,7 @@ class Svg(object):
self.id = '#chart-%s ' % graph.uuid self.id = '#chart-%s ' % graph.uuid
else: else:
self.id = '' self.id = ''
self.processing_instructions = [ self.processing_instructions = []
etree.ProcessingInstruction(
u('xml'), u("version='1.0' encoding='utf-8'"))]
if etree.lxml: if etree.lxml:
attrs = { attrs = {
'nsmap': { 'nsmap': {
@ -323,16 +321,25 @@ class Svg(object):
args = { args = {
'encoding': 'utf-8' 'encoding': 'utf-8'
} }
svg = b''
if etree.lxml: if etree.lxml:
args['pretty_print'] = pretty_print 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) self.root, **args)
if 'xml_declaration' in args:
args.pop('xml_declaration')
if not self.graph.disable_xml_declaration: if not self.graph.disable_xml_declaration:
svg = b'\n'.join( svg = b'\n'.join(
[etree.tostring( [etree.tostring(
pi, **args) pi, **args)
for pi in self.processing_instructions] for pi in self.processing_instructions] + [svg]
) + b'\n' + svg )
if self.graph.disable_xml_declaration or is_unicode: if self.graph.disable_xml_declaration or is_unicode:
svg = svg.decode('utf-8') svg = svg.decode('utf-8')
return svg return svg

Loading…
Cancel
Save