1 """NDG XACML package
2
3 NERC DataGrid
4 """
5 __author__ = "P J Kershaw"
6 __date__ = "16/03/10"
7 __copyright__ = "(C) 2010 Science and Technology Facilities Council"
8 __contact__ = "Philip.Kershaw@stfc.ac.uk"
9 __license__ = "BSD - see LICENSE file in top-level directory"
10 __contact__ = "Philip.Kershaw@stfc.ac.uk"
11 __revision__ = "$Id: __init__.py 8010 2012-01-30 16:24:06Z rwilkinson $"
13 """Base class for XACML package exception types"""
14
16 """Configuration options
17 @type use_lxml: bool
18 @cvar use_lxml: Controls whether lxml.etree should be imported instead of
19 etree. lxml is required for XPath expressions with conditions.
20 """
21 use_lxml = None
22
24 """Imports ElementTree or the lxml ElementTree API depending on the
25 Config.use_lxml value and whether the lxml package is found.
26 @rtype: module
27 @return: the element tree module that has been imported
28 """
29 if Config.use_lxml is not None:
30 if Config.use_lxml:
31 from lxml import etree as ElementTree
32 else:
33 try:
34 from xml.etree import ElementTree
35 except ImportError:
36
37 import ElementTree
38 else:
39 Config.use_lxml = False
40 try:
41 from lxml import etree as ElementTree
42 Config.use_lxml = True
43 except ImportError:
44 try:
45 from xml.etree import ElementTree
46 except ImportError:
47
48 import ElementTree
49 return ElementTree
50