diff options
author | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-01-12 12:35:28 +0100 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-01-12 16:34:00 +0100 |
commit | cecb3c86b3500903481ef7fb953fb91afa55b0a4 (patch) | |
tree | b08f4d745cdf04fb7e17beaf7fbc7a82df11b41b /rdflib/compat.py | |
parent | f469bb04e9e75d407f047f081ae5003feb712a34 (diff) | |
download | rdflib-cecb3c86b3500903481ef7fb953fb91afa55b0a4.tar.gz |
be more compatible when importing elementtree, and only in one place
fixes #606
Diffstat (limited to 'rdflib/compat.py')
-rw-r--r-- | rdflib/compat.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/rdflib/compat.py b/rdflib/compat.py index 6c714894..668f5f1a 100644 --- a/rdflib/compat.py +++ b/rdflib/compat.py @@ -23,3 +23,34 @@ else: def numeric_greater(a, b): return a > b + + +try: + from lxml import etree +except ImportError: + try: + # Python 2.5 + import xml.etree.cElementTree as etree + except ImportError: + try: + # Python 2.5 + import xml.etree.ElementTree as etree + except ImportError: + try: + # normal cElementTree install + import cElementTree as etree + except ImportError: + try: + # normal ElementTree install + import elementtree.ElementTree as etree + except ImportError: + raise Exception("Failed to import ElementTree from any known place") + +try: + etree_register_namespace = etree.register_namespace +except AttributeError: + + import xml.etree.ElementTree as etreenative + + def etree_register_namespace(prefix, uri): + etreenative._namespace_map[uri] = prefix |