1
0
mirror of https://github.com/djohnlewis/stackdump synced 2025-01-22 22:51:36 +00:00
stackdump/python/packages/markdown/etree_loader.py
Samuel Lai 993bee4fc1 Added markdown parsing for comments so links in comments now appear properly.
Also rewrote part of the HTML rewriting code so it doesn't introduce an additional wrapping element in the output which was added due to a html5lib requirements on input.
2012-12-15 21:43:06 +11:00

32 lines
1.3 KiB
Python

## 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