1
2from markdown import message, CRITICAL
3import sys
4
5## Import
6def importETree():
7    """Import the best implementation of ElementTree, return a module object."""
8    etree_in_c = None
9    try: # Is it Python 2.5+ with C implemenation of ElementTree installed?
10        import xml.etree.cElementTree as etree_in_c
11    except ImportError:
12        try: # Is it Python 2.5+ with Python implementation of ElementTree?
13            import xml.etree.ElementTree as etree
14        except ImportError:
15            try: # An earlier version of Python with cElementTree installed?
16                import cElementTree as etree_in_c
17            except ImportError:
18                try: # An earlier version of Python with Python ElementTree?
19                    import elementtree.ElementTree as etree
20                except ImportError:
21                    message(CRITICAL, "Failed to import ElementTree")
22                    sys.exit(1)
23    if etree_in_c and etree_in_c.VERSION < "1.0":
24        message(CRITICAL, "For cElementTree version 1.0 or higher is required.")
25        sys.exit(1)
26    elif etree_in_c :
27        return etree_in_c
28    elif etree.VERSION < "1.1":
29        message(CRITICAL, "For ElementTree version 1.1 or higher is required")
30        sys.exit(1)
31    else :
32        return etree
33
34