From 00fb296ed706b577ee70bdfd35d47ca7f255e427 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Mon, 9 May 2011 13:56:53 +0200 Subject: [PATCH 1/7] take encryption function from globals() rather than locals() --- radicale/acl/htpasswd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/acl/htpasswd.py b/radicale/acl/htpasswd.py index 70197d1..d6600ee 100644 --- a/radicale/acl/htpasswd.py +++ b/radicale/acl/htpasswd.py @@ -65,5 +65,5 @@ def has_right(owner, user, password): if line.strip(): login, hash_value = line.strip().split(":") if login == user and (not PERSONAL or user == owner): - return locals()["_%s" % ENCRYPTION](hash_value, password) + return globals()["_%s" % ENCRYPTION](hash_value, password) return False From 4212f6dfe0b5d7d1e1859638b6211667416e86d9 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Mon, 9 May 2011 14:04:17 +0200 Subject: [PATCH 2/7] the replaced syntax is deprecated --- radicale/xmlutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index e582dc0..912e6b3 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -194,7 +194,7 @@ def proppatch(path, xml_request, calendar): for action in ("set", "remove"): action_element = root.find(_tag("D", action)) - if action_element: + if action_element is not None: prop_element = action_element.find(_tag("D", "prop")) prop_list = prop_element.getchildren() props.extend(prop.tag for prop in prop_list) From 6b5db413c515309a2e0659013874f231a0d6c8d3 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Mon, 9 May 2011 16:43:41 +0200 Subject: [PATCH 3/7] logging and debugging fixes * optparse values may not be strings, ConfigParser requires strings * forcing DEBUG level should work for all handlers regardless of configuration source (file, command line options) --- radicale.py | 4 ++-- radicale/log.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/radicale.py b/radicale.py index 7802576..8ac9bdb 100755 --- a/radicale.py +++ b/radicale.py @@ -81,10 +81,10 @@ for option in parser.option_list: if key: section = "logging" if key == "debug" else "server" value = getattr(options, key) - radicale.config.set(section, key, value) + radicale.config.set(section, key, str(value)) # Start logging -radicale.log.start(options.debug) +radicale.log.start() # Fork if Radicale is launched as daemon if options.daemon: diff --git a/radicale/log.py b/radicale/log.py index 3d36f9f..19ec046 100644 --- a/radicale/log.py +++ b/radicale/log.py @@ -35,10 +35,8 @@ from radicale import config LOGGER = logging.getLogger() FILENAME = os.path.expanduser(config.get("logging", "config")) -def start(debug=False): +def start(): """Start the logging according to the configuration.""" - if debug: - LOGGER.setLevel(logging.DEBUG) if os.path.exists(FILENAME): # Configuration taken from file @@ -48,3 +46,8 @@ def start(debug=False): handler = logging.StreamHandler(sys.stdout) handler.setFormatter(logging.Formatter("%(message)s")) LOGGER.addHandler(handler) + + if config.getboolean("logging", "debug"): + LOGGER.setLevel(logging.DEBUG) + for handler in LOGGER.handlers: + handler.setLevel(logging.DEBUG) From 32b01d60fcdf68885ff3b833e348928b656cf729 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Mon, 9 May 2011 16:51:58 +0200 Subject: [PATCH 4/7] 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")) From 4230ec2fa9dee7a561c10d5afd30f711d2a1dc09 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Mon, 9 May 2011 17:02:31 +0200 Subject: [PATCH 5/7] Use pretty namespace prefixes in output. --- radicale/xmlutils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 97cafbd..01a3a07 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -38,6 +38,10 @@ NAMESPACES = { "CS": "http://calendarserver.org/ns/"} +for short, url in NAMESPACES.iteritems(): + ET._namespace_map[url] = short + + def _et_indent(elem, level=0): i = "\n" + level * " " if len(elem): From 0d8fa5db6b103fe2c6e5919eb2357ae203836174 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Tue, 10 May 2011 14:21:13 +0200 Subject: [PATCH 6/7] More deprecation fixes xmlutils.py:116: DeprecationWarning: This method will be removed in future versions. Use 'list(elem)' or iteration over elem instead. prop_list = prop_element.getchildren() --- radicale/xmlutils.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 01a3a07..0efe37e 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -113,9 +113,8 @@ def propfind(path, xml_request, calendar, depth): root = ET.fromstring(xml_request) prop_element = root.find(_tag("D", "prop")) - prop_list = prop_element.getchildren() - props = [prop.tag for prop in prop_list] - + props = [prop.tag for prop in prop_element] + # Writing answer multistatus = ET.Element(_tag("D", "multistatus")) @@ -222,8 +221,7 @@ def proppatch(path, xml_request, calendar): action_element = root.find(_tag("D", action)) if action_element is not None: prop_element = action_element.find(_tag("D", "prop")) - prop_list = prop_element.getchildren() - props.extend(prop.tag for prop in prop_list) + props.extend(prop.tag for prop in prop_element) # Writing answer multistatus = ET.Element(_tag("D", "multistatus")) @@ -276,8 +274,7 @@ def report(path, xml_request, calendar): root = ET.fromstring(xml_request) prop_element = root.find(_tag("D", "prop")) - prop_list = prop_element.getchildren() - props = [prop.tag for prop in prop_list] + props = [prop.tag for prop in prop_element] if calendar: if root.tag == _tag("C", "calendar-multiget"): From 485e375139c870941e2a7fc11c5ecc974be724a7 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Tue, 10 May 2011 19:16:03 +0200 Subject: [PATCH 7/7] Minor py3k compatibility changes: iteritems() doesn't exist on Python 3.x, logged text must be Unicode. --- radicale/__init__.py | 6 +++++- radicale/xmlutils.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index e446b6c..fcf6265 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -190,7 +190,11 @@ class Application(object): # Set content length if answer: - log.LOGGER.debug("Response content:\n%s" % answer) + # decoding the answer for logging purposes on Python 3 + log_answer = answer + if not isinstance(log_answer, str): + log_answer = log_answer.decode(config.get("encoding", "request")) + log.LOGGER.debug("Response content:\n%s" % log_answer) headers["Content-Length"] = "%i" % len(answer) # Start response diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 0efe37e..2806a32 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -38,7 +38,7 @@ NAMESPACES = { "CS": "http://calendarserver.org/ns/"} -for short, url in NAMESPACES.iteritems(): +for short, url in NAMESPACES.items(): ET._namespace_map[url] = short