diff options
author | Waylan Limberg <waylan@gmail.com> | 2013-02-26 11:49:18 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2013-02-26 11:49:18 -0500 |
commit | b37ab16ba56ac6fe4e64f87521996bad323058f2 (patch) | |
tree | 2bf4432483408411e9210a3ad48fdabb4bc52c9f | |
parent | 7f75a936f340600ad599a24c548ebcea2171dc25 (diff) | |
download | markdown-b37ab16ba56ac6fe4e64f87521996bad323058f2.tar.gz markdown-b37ab16ba56ac6fe4e64f87521996bad323058f2.tar.bz2 markdown-b37ab16ba56ac6fe4e64f87521996bad323058f2.zip |
Simlify importing ElementTree
As we no longer support older python versions, importing
ElementTree is much simpler. The documented way for
extensions to use etree still remains the same.
-rw-r--r-- | markdown/etree_loader.py | 31 | ||||
-rw-r--r-- | markdown/util.py | 15 |
2 files changed, 13 insertions, 33 deletions
diff --git a/markdown/etree_loader.py b/markdown/etree_loader.py deleted file mode 100644 index f605aa2..0000000 --- a/markdown/etree_loader.py +++ /dev/null @@ -1,31 +0,0 @@ - -## Import -def importETree(): - """Import the best implementation of ElementTree, return a module object.""" - etree_in_c = None - try: # Is it Python 2.5+ with C implemenation of ElementTree installed? - import xml.etree.cElementTree as etree_in_c - from xml.etree.ElementTree import Comment - except ImportError: - try: # Is it Python 2.5+ with Python implementation of ElementTree? - import xml.etree.ElementTree as etree - except ImportError: - try: # An earlier version of Python with cElementTree installed? - import cElementTree as etree_in_c - from elementtree.ElementTree import Comment - except ImportError: - try: # An earlier version of Python with Python ElementTree? - import elementtree.ElementTree as etree - except ImportError: - raise ImportError("Failed to import ElementTree") - if etree_in_c: - if etree_in_c.VERSION < "1.0.5": - raise RuntimeError("cElementTree version 1.0.5 or higher is required.") - # Third party serializers (including ours) test with non-c Comment - etree_in_c.test_comment = Comment - return etree_in_c - elif etree.VERSION < "1.1": - raise RuntimeError("ElementTree version 1.1 or higher is required") - else: - return etree - diff --git a/markdown/util.py b/markdown/util.py index 12dcbd5..34333f0 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import re -import etree_loader """ @@ -42,7 +41,19 @@ RTL_BIDI_RANGES = ( (u'\u0590', u'\u07FF'), # Extensions should use "markdown.util.etree" instead of "etree" (or do `from # markdown.util import etree`). Do not import it by yourself. -etree = etree_loader.importETree() +try: # Is the C implemenation of ElementTree available? + import xml.etree.cElementTree as etree + from xml.etree.ElementTree import Comment + # Serializers (including ours) test with non-c Comment + etree.test_comment = Comment + if etree.VERSION < "1.0.5": + raise RuntimeError("cElementTree version 1.0.5 or higher is required.") +except (ImportError, RuntimeError): + # Use the Python implementation of ElementTree? + import xml.etree.ElementTree as etree + if etree.VERSION < "1.1": + raise RuntimeError("ElementTree version 1.1 or higher is required") + """ AUXILIARY GLOBAL FUNCTIONS |