This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we are showing it without any
pretty colors.
Highlight
it anyway.
| 1 |
|
| 2 |
## Import |
| 3 |
def importETree(): |
| 4 |
"""Import the best implementation of ElementTree, return a module object.""" |
| 5 |
etree_in_c = None |
| 6 |
try: # Is it Python 2.5+ with C implemenation of ElementTree installed? |
| 7 |
import xml.etree.cElementTree as etree_in_c |
| 8 |
from xml.etree.ElementTree import Comment |
| 9 |
except ImportError: |
| 10 |
try: # Is it Python 2.5+ with Python implementation of ElementTree? |
| 11 |
import xml.etree.ElementTree as etree |
| 12 |
except ImportError: |
| 13 |
try: # An earlier version of Python with cElementTree installed? |
| 14 |
import cElementTree as etree_in_c |
| 15 |
from elementtree.ElementTree import Comment |
| 16 |
except ImportError: |
| 17 |
try: # An earlier version of Python with Python ElementTree? |
| 18 |
import elementtree.ElementTree as etree |
| 19 |
except ImportError: |
| 20 |
raise ImportError("Failed to import ElementTree") |
| 21 |
if etree_in_c: |
| 22 |
if etree_in_c.VERSION < "1.0.5": |
| 23 |
raise RuntimeError("cElementTree version 1.0.5 or higher is required.") |
| 24 |
# Third party serializers (including ours) test with non-c Comment |
| 25 |
etree_in_c.test_comment = Comment |
| 26 |
return etree_in_c |
| 27 |
elif etree.VERSION < "1.1": |
| 28 |
raise RuntimeError("ElementTree version 1.1 or higher is required") |
| 29 |
else: |
| 30 |
return etree |