Browse Source

Try to fix missing register_namespace in python 2.6

pull/130/head
Florian Mounier 11 years ago
parent
commit
2ae67e185a
  1. 10
      demo/moulinrouge/__init__.py
  2. 8
      pygal/svg.py

10
demo/moulinrouge/__init__.py

@ -16,11 +16,12 @@
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
from flask import Flask, render_template, Response from flask import Flask, render_template, Response, request
import pygal import pygal
from pygal.config import Config from pygal.config import Config
from pygal.util import cut from pygal.util import cut
from pygal.graph import CHARTS_NAMES from pygal.graph import CHARTS_NAMES
from pygal.etree import etree
from pygal.style import styles, parametric_styles from pygal.style import styles, parametric_styles
from base64 import ( from base64 import (
urlsafe_b64encode as b64encode, urlsafe_b64encode as b64encode,
@ -46,6 +47,13 @@ def create_app():
app = Flask(__name__) 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): def _random(data, order):
max = 10 ** order max = 10 ** order
min = 10 ** random.randrange(0, order) min = 10 ** random.randrange(0, order)

8
pygal/svg.py

@ -59,7 +59,10 @@ class Svg(object):
attrs = { attrs = {
'xmlns': self.ns '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 = etree.Element('svg', **attrs)
self.root.attrib['id'] = self.id.lstrip('#').rstrip() self.root.attrib['id'] = self.id.lstrip('#').rstrip()
@ -150,7 +153,8 @@ class Svg(object):
attrib[key.rstrip('_')] = attrib[key] attrib[key.rstrip('_')] = attrib[key]
del attrib[key] del attrib[key]
elif key == 'href': 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] del attrib[key]
return etree.SubElement(parent, tag, attrib) return etree.SubElement(parent, tag, attrib)

Loading…
Cancel
Save