view sword2-libraries-pyinstaller-compatible/sword2/compatible_libs.py @ 22:d1752c7031e4 timeouts tip

Updated .hgignore to ignore sword2_logging.conf and anything in .cache
author Steve Welburn <stephen.welburn@eecs.qmul.ac.uk>
date Tue, 22 Jan 2013 14:43:42 +0000
parents 8b69bba225c9
children
line wrap: on
line source
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Provides the module with access to certain libraries that have more than one suitable implementation, in a optimally
degredating manner.

Provides - `etree` and `json`

`etree` can be from any of the following, if found in the local environment:
    `lxml`
    `xml.etree`
    `elementtree`
    `cElementTree`

`json` can be from any of the following:
    `json` (python >= 2.6)
    `simplejson`
    
If no suitable library is found, then it will pass back `None`
"""

from sword2_logging import logging 

cl_l = logging.getLogger(__name__)

try:
    from lxml import etree
except ImportError:
    try:
        # Python >= 2.5
        from xml.etree import ElementTree as etree
    except ImportError:
        try:
            from elementtree import ElementTree as etree
        except ImportError:
            try:
                import cElementTree as etree
            except ImportError:
                cl_l.error("Couldn't find a suitable ElementTree library to use in this environment.")
                etree = None

try:
    import json
except ImportError:
    try:
        import simplejson as json
    except ImportError:
        cl_l.error("Couldn't find a suitable simplejson-like library to use to serialise JSON")
        json = None