Package sword2 :: Module compatible_libs
[hide private]
[frames] | no frames]

Source Code for Module sword2.compatible_libs

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3   
 4  """ 
 5  Provides the module with access to certain libraries that have more than one suitable implementation, in a optimally 
 6  degredating manner. 
 7   
 8  Provides - `etree` and `json` 
 9   
10  `etree` can be from any of the following, if found in the local environment: 
11      `lxml` 
12      `xml.etree` 
13      `elementtree` 
14      `cElementTree` 
15   
16  `json` can be from any of the following: 
17      `json` (python >= 2.6) 
18      `simplejson` 
19       
20  If no suitable library is found, then it will pass back `None` 
21  """ 
22   
23  from sword2_logging import logging  
24   
25  cl_l = logging.getLogger(__name__) 
26   
27  try: 
28      from lxml import etree 
29  except ImportError: 
30      try: 
31          # Python >= 2.5 
32          from xml.etree import ElementTree as etree 
33      except ImportError: 
34          try: 
35              from elementtree import ElementTree as etree 
36          except ImportError: 
37              try: 
38                  import cElementTree as etree 
39              except ImportError: 
40                  cl_l.error("Couldn't find a suitable ElementTree library to use in this environment.") 
41                  etree = None 
42   
43  try: 
44      import json 
45  except ImportError: 
46      try: 
47          import simplejson as json 
48      except ImportError: 
49          cl_l.error("Couldn't find a suitable simplejson-like library to use to serialise JSON") 
50          json = None 
51