Bumped version to 0.2.dev and added tagging of releases with date.
[django-cas-provider.git] / cas_provider / etree.py
1 # Import etree from anywhere
2 try:
3     # lxml http://codespeak.net/lxml/
4     from lxml import etree
5     
6     # Define register_namespace function and ElementRoot for proper serialization
7     NSMAP = {}
8     def register_namespace(prefix, uri):
9         NSMAP[prefix] = uri
10     
11     def ElementRoot(*args, **kwargs):
12         kwargs['nsmap'] = NSMAP
13         return etree.Element(*args, **kwargs)
14
15 except ImportError:
16     try:
17         # normal cElementTree install
18         import cElementTree as etree
19     except ImportError:
20         # normal ElementTree install
21         import elementtree.ElementTree as etree
22
23     try:
24         register_namespace = ET.register_namespace
25     except AttributeError:
26         def register_namespace(prefix, uri):
27             ET._namespace_map[uri] = prefix
28
29     def ElementRoot(*args, **kwargs):
30         return etree.Element(*args, **kwargs)
31
32 __all__ = ('etree', 'register_namespace', 'ElementRoot')