From e7ba2ab78b18459efd970d7fd6596c85307ed0f4 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 13 May 2011 22:03:50 +0200 Subject: [PATCH] Register XML namespaces cleanly with Python 2.7+ and 3.2+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old code was relying on a largely used but private variable. Moreover, it was bugged with the empty string for "D", adding ":" instead of nothing at the beginning of tag names with Python 2.6, 3.0 and 3.1, breaking at least the Lightning support. This new code still relies on the private variable for old Python versions, but uses the good-way™ for actual and future versions. No default namespace is used for old versions, but that's not that bad. --- radicale/xmlutils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index fdc77d9..cbdaa54 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -40,7 +40,12 @@ NAMESPACES = { for short, url in NAMESPACES.items(): - ET._namespace_map[url] = "" if short == "D" else short + if hasattr(ET, "register_namespace"): + # Register namespaces cleanly with Python 2.7+ and 3.2+ ... + ET.register_namespace("" if short == "D" else short, url) + else: + # ... and badly with Python 2.6- and 3.1- + ET._namespace_map[url] = short def _pretty_xml(element, level=0):