Browse Source

Wrap etree

pull/130/head
Florian Mounier 11 years ago
parent
commit
b32bb1c256
  1. 10
      pygal/_compat.py
  2. 52
      pygal/etree.py
  3. 3
      pygal/graph/frenchmap.py
  4. 2
      pygal/graph/supranationalworldmap.py
  5. 2
      pygal/graph/worldmap.py
  6. 3
      pygal/svg.py
  7. 1
      pygal/test/__init__.py
  8. 10
      relauncher

10
pygal/_compat.py

@ -16,19 +16,9 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from collections import Iterable
try:
if os.getenv('NO_LXML', None):
raise ImportError('Explicit lxml bypass')
from lxml import etree
etree.lxml = True
except ImportError:
from xml.etree import ElementTree as etree
etree.lxml = False
if sys.version_info[0] == 3:
base = (str, bytes)

52
pygal/etree.py

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012-2014 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
import os
class Etree(object):
def __init__(self):
from xml.etree import ElementTree as _py_etree
self._py_etree = _py_etree
try:
from lxml import etree as _lxml_etree
self._lxml_etree = _lxml_etree
except ImportError:
self._lxml_etree = None
if os.getenv('NO_LXML', None):
self._etree = self._py_etree
else:
self._etree = self._lxml_etree or self._py_etree
self.lxml = self._etree is self._lxml_etree
def __getattribute__(self, attr):
if (attr not in object.__getattribute__(self, '__dict__') and
attr not in Etree.__dict__):
return object.__getattribute__(self._etree, attr)
return object.__getattribute__(self, attr)
def to_lxml(self):
self._etree = self._lxml_etree
self.lxml = True
def to_etree(self):
self._etree = self._py_etree
self.lxml = False
etree = Etree()

3
pygal/graph/frenchmap.py

@ -26,7 +26,8 @@ from collections import defaultdict
from pygal.ghost import ChartCollection
from pygal.util import cut, cached_property, decorate
from pygal.graph.graph import Graph
from pygal._compat import u, etree
from pygal._compat import u
from pygal.etree import etree
from numbers import Number
import os

2
pygal/graph/supranationalworldmap.py

@ -25,7 +25,7 @@ from __future__ import division
from pygal.graph.worldmap import Worldmap
from pygal.i18n import SUPRANATIONAL
from pygal.util import cut, decorate
from pygal._compat import etree
from pygal.etree import etree
import os
with open(os.path.join(

2
pygal/graph/worldmap.py

@ -25,7 +25,7 @@ from __future__ import division
from pygal.util import cut, cached_property, decorate
from pygal.graph.graph import Graph
from pygal.i18n import COUNTRIES
from pygal._compat import etree
from pygal.etree import etree
import os
with open(os.path.join(

3
pygal/svg.py

@ -22,7 +22,8 @@ Svg helper
"""
from __future__ import division
from pygal._compat import to_str, u, etree
from pygal._compat import to_str, u
from pygal.etree import etree
import io
import os
import json

1
pygal/test/__init__.py

@ -22,7 +22,6 @@ from pygal.util import cut
from datetime import datetime
from pygal.i18n import COUNTRIES
from pygal.graph.frenchmap import DEPARTMENTS, REGIONS
from pygal._compat import etree
def get_data(i):

10
relauncher

@ -1,10 +0,0 @@
#!/bin/zsh
pkill -f livereload
pkill -f reload
pkill -f SimpleHTTPServer
livereload&
reload ./demo/simple_test.py **/*.{py,js,css}&
python -m SimpleHTTPServer 1515&
sleep 1
chromium http://localhost:1515/&
Loading…
Cancel
Save