From 1fe011020b534dbe1f8f3ef02eab4c016043d7d9 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 26 Sep 2020 22:08:21 +0200 Subject: [PATCH] Single element in PROPPATCH response Instead of multiple elements with the same status --- radicale/app/proppatch.py | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/radicale/app/proppatch.py b/radicale/app/proppatch.py index 3ec10c3..9c6b591 100644 --- a/radicale/app/proppatch.py +++ b/radicale/app/proppatch.py @@ -27,29 +27,6 @@ from radicale import storage, xmlutils from radicale.log import logger -def xml_add_propstat_to(element, tag, status_number): - """Add a PROPSTAT response structure to an element. - - The PROPSTAT answer structure is defined in rfc4918-9.1. It is added to the - given ``element``, for the following ``tag`` with the given - ``status_number``. - - """ - propstat = ET.Element(xmlutils.make_clark("D:propstat")) - element.append(propstat) - - prop = ET.Element(xmlutils.make_clark("D:prop")) - propstat.append(prop) - - clark_tag = xmlutils.make_clark(tag) - prop_tag = ET.Element(clark_tag) - prop.append(prop_tag) - - status = ET.Element(xmlutils.make_clark("D:status")) - status.text = xmlutils.make_response(status_number) - propstat.append(status) - - def xml_proppatch(base_prefix, path, xml_request, collection): """Read and answer PROPPATCH requests. @@ -68,16 +45,25 @@ def xml_proppatch(base_prefix, path, xml_request, collection): href.text = xmlutils.make_href(base_prefix, path) response.append(href) + # Create D:propstat element for props with status 200 OK + propstat = ET.Element(xmlutils.make_clark("D:propstat")) + status = ET.Element(xmlutils.make_clark("D:status")) + status.text = xmlutils.make_response(200) + props_ok = ET.Element(xmlutils.make_clark("D:prop")) + propstat.append(props_ok) + propstat.append(status) + response.append(propstat) + new_props = collection.get_meta() for short_name, value in props_to_set.items(): new_props[short_name] = value - xml_add_propstat_to(response, short_name, 200) + props_ok.append(ET.Element(xmlutils.make_clark(short_name))) for short_name in props_to_remove: try: del new_props[short_name] except KeyError: pass - xml_add_propstat_to(response, short_name, 200) + props_ok.append(ET.Element(xmlutils.make_clark(short_name))) radicale_item.check_and_sanitize_props(new_props) collection.set_meta(new_props)