From 32b01d60fcdf68885ff3b833e348928b656cf729 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Mon, 9 May 2011 16:51:58 +0200 Subject: [PATCH] in debug mode, prettify XML output for analysis --- radicale/xmlutils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 912e6b3..97cafbd 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -38,6 +38,22 @@ NAMESPACES = { "CS": "http://calendarserver.org/ns/"} +def _et_indent(elem, level=0): + i = "\n" + level * " " + if len(elem): + if not elem.text or not elem.text.strip(): + elem.text = i + " " + if not elem.tail or not elem.tail.strip(): + elem.tail = i + for elem in elem: + _et_indent(elem, level+1) + if not elem.tail or not elem.tail.strip(): + elem.tail = i + else: + if level and (not elem.tail or not elem.tail.strip()): + elem.tail = i + + def _tag(short_name, local): """Get XML Clark notation {uri(``short_name``)}``local``.""" return "{%s}%s" % (NAMESPACES[short_name], local) @@ -77,6 +93,9 @@ def delete(path, calendar): status.text = _response(200) response.append(status) + if config.getboolean("logging", "debug"): + _et_indent(multistatus) + return ET.tostring(multistatus, config.get("encoding", "request")) @@ -179,6 +198,9 @@ def propfind(path, xml_request, calendar, depth): status.text = _response(200) propstat.append(status) + if config.getboolean("logging", "debug"): + _et_indent(multistatus) + return ET.tostring(multistatus, config.get("encoding", "request")) @@ -223,6 +245,9 @@ def proppatch(path, xml_request, calendar): status.text = _response(200) propstat.append(status) + if config.getboolean("logging", "debug"): + _et_indent(multistatus) + return ET.tostring(multistatus, config.get("encoding", "request")) @@ -303,4 +328,7 @@ def report(path, xml_request, calendar): status.text = _response(200) propstat.append(status) + if config.getboolean("logging", "debug"): + _et_indent(multistatus) + return ET.tostring(multistatus, config.get("encoding", "request"))