From: zuber Date: Thu, 15 Oct 2009 17:09:15 +0000 (+0200) Subject: Changed xml.py module name to etree.py because it was conflicting with xml package... X-Git-Tag: 22.4~32^2~18^2~1^2~5 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/b012d252975d36d17a2368bd0ee79088a2407bb0 Changed xml.py module name to etree.py because it was conflicting with xml package in python std. Require elementtree or lxml because they have proper namespace handling. --- diff --git a/cas_provider/etree.py b/cas_provider/etree.py new file mode 100644 index 0000000..eb6f0be --- /dev/null +++ b/cas_provider/etree.py @@ -0,0 +1,32 @@ +# Import etree from anywhere +try: + # lxml http://codespeak.net/lxml/ + from lxml import etree + + # Define register_namespace function and ElementRoot for proper serialization + NSMAP = {} + def register_namespace(prefix, uri): + NSMAP[prefix] = uri + + def ElementRoot(*args, **kwargs): + kwargs['nsmap'] = NSMAP + return etree.Element(*args, **kwargs) + +except ImportError: + try: + # normal cElementTree install + import cElementTree as etree + except ImportError: + # normal ElementTree install + import elementtree.ElementTree as etree + + try: + register_namespace = ET.register_namespace + except AttributeError: + def register_namespace(prefix, uri): + ET._namespace_map[uri] = prefix + + def ElementRoot(*args, **kwargs): + return etree.Element(*args, **kwargs) + +__all__ = ('etree', 'register_namespace', 'ElementRoot') diff --git a/cas_provider/models.py b/cas_provider/models.py index eae9cf6..5d09912 100644 --- a/cas_provider/models.py +++ b/cas_provider/models.py @@ -3,7 +3,7 @@ from django.contrib.auth.models import User from django.conf import settings from django.core.urlresolvers import get_callable -from cas_provider.xml import etree, register_namespace, ElementRoot +from cas_provider.etree import etree, register_namespace, ElementRoot class ServiceTicket(models.Model): user = models.ForeignKey(User) diff --git a/cas_provider/xml.py b/cas_provider/xml.py deleted file mode 100644 index da56a97..0000000 --- a/cas_provider/xml.py +++ /dev/null @@ -1,40 +0,0 @@ -# Import etree from anywhere -try: - # lxml http://codespeak.net/lxml/ - from lxml import etree - - # Define register_namespace function and ElementRoot for proper serialization - NSMAP = {} - def register_namespace(prefix, uri): - NSMAP[prefix] = uri - - def ElementRoot(*args, **kwargs): - kwargs['nsmap'] = NSMAP - return etree.Element(*args, **kwargs) - -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: - # normal ElementTree install - import elementtree.ElementTree as etree - - try: - register_namespace = ET.register_namespace - except AttributeError: - def register_namespace(prefix, uri): - ET._namespace_map[uri] = prefix - - def ElementRoot(*args, **kwargs): - return etree.Element(*args, **kwargs) - -__all__ = ('etree', 'register_namespace', 'ElementRoot')