From 2ae67e185a8e350725dfc891e07669d82b8e9339 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Thu, 5 Jun 2014 13:38:23 +0200 Subject: [PATCH] Try to fix missing register_namespace in python 2.6 --- demo/moulinrouge/__init__.py | 10 +++++++++- pygal/svg.py | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/demo/moulinrouge/__init__.py b/demo/moulinrouge/__init__.py index 359a63b..1c50ea4 100644 --- a/demo/moulinrouge/__init__.py +++ b/demo/moulinrouge/__init__.py @@ -16,11 +16,12 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . -from flask import Flask, render_template, Response +from flask import Flask, render_template, Response, request import pygal from pygal.config import Config from pygal.util import cut from pygal.graph import CHARTS_NAMES +from pygal.etree import etree from pygal.style import styles, parametric_styles from base64 import ( urlsafe_b64encode as b64encode, @@ -46,6 +47,13 @@ def create_app(): app = Flask(__name__) + @app.before_request + def before_request(): + if request.args.get('etree'): + etree.to_etree() + else: + etree.to_lxml() + def _random(data, order): max = 10 ** order min = 10 ** random.randrange(0, order) diff --git a/pygal/svg.py b/pygal/svg.py index f7b9789..4a55454 100644 --- a/pygal/svg.py +++ b/pygal/svg.py @@ -59,7 +59,10 @@ class Svg(object): attrs = { 'xmlns': self.ns } - etree.register_namespace('xlink', self.xlink_ns) + if hasattr(etree, 'register_namespace'): + etree.register_namespace('xlink', self.xlink_ns) + else: + etree._namespace_map[self.xlink_ns] = 'xlink' self.root = etree.Element('svg', **attrs) self.root.attrib['id'] = self.id.lstrip('#').rstrip() @@ -150,7 +153,8 @@ class Svg(object): attrib[key.rstrip('_')] = attrib[key] del attrib[key] elif key == 'href': - attrib['{http://www.w3.org/1999/xlink}' + key] = attrib[key] + attrib[etree.QName( + 'http://www.w3.org/1999/xlink', key)] = attrib[key] del attrib[key] return etree.SubElement(parent, tag, attrib)