16516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru 26516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Querufrom markdown import message, CRITICAL 36516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queruimport sys 46516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru 56516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru## Import 66516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Querudef importETree(): 76516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru """Import the best implementation of ElementTree, return a module object.""" 86516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru etree_in_c = None 96516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru try: # Is it Python 2.5+ with C implemenation of ElementTree installed? 106516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru import xml.etree.cElementTree as etree_in_c 116516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru except ImportError: 126516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru try: # Is it Python 2.5+ with Python implementation of ElementTree? 136516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru import xml.etree.ElementTree as etree 146516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru except ImportError: 156516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru try: # An earlier version of Python with cElementTree installed? 166516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru import cElementTree as etree_in_c 176516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru except ImportError: 186516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru try: # An earlier version of Python with Python ElementTree? 196516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru import elementtree.ElementTree as etree 206516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru except ImportError: 216516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru message(CRITICAL, "Failed to import ElementTree") 226516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru sys.exit(1) 236516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru if etree_in_c and etree_in_c.VERSION < "1.0": 246516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru message(CRITICAL, "For cElementTree version 1.0 or higher is required.") 256516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru sys.exit(1) 266516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru elif etree_in_c : 276516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru return etree_in_c 286516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru elif etree.VERSION < "1.1": 296516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru message(CRITICAL, "For ElementTree version 1.1 or higher is required") 306516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru sys.exit(1) 316516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru else : 326516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru return etree 336516b99bb74dfb7187a08f7090bf7ca22a006f15Jean-Baptiste Queru 34