Cosmetic changes

This commit is contained in:
Unrud 2020-01-21 19:40:02 +01:00
parent fc180266d5
commit db7587c593
7 changed files with 35 additions and 38 deletions

View File

@ -28,6 +28,7 @@ import contextlib
import os import os
import signal import signal
import socket import socket
import sys
from radicale import VERSION, config, log, server, storage from radicale import VERSION, config, log, server, storage
from radicale.log import logger from radicale.log import logger
@ -113,7 +114,7 @@ def run():
configuration.update(arguments_config, "arguments") configuration.update(arguments_config, "arguments")
except Exception as e: except Exception as e:
logger.fatal("Invalid configuration: %s", e, exc_info=True) logger.fatal("Invalid configuration: %s", e, exc_info=True)
exit(1) sys.exit(1)
# Configure logging # Configure logging
log.set_level(configuration.get("logging", "level")) log.set_level(configuration.get("logging", "level"))
@ -128,11 +129,11 @@ def run():
with storage_.acquire_lock("r"): with storage_.acquire_lock("r"):
if not storage_.verify(): if not storage_.verify():
logger.fatal("Storage verifcation failed") logger.fatal("Storage verifcation failed")
exit(1) sys.exit(1)
except Exception as e: except Exception as e:
logger.fatal("An exception occurred during storage verification: " logger.fatal("An exception occurred during storage verification: "
"%s", e, exc_info=True) "%s", e, exc_info=True)
exit(1) sys.exit(1)
return return
# Create a socket pair to notify the server of program shutdown # Create a socket pair to notify the server of program shutdown
@ -149,7 +150,7 @@ def run():
except Exception as e: except Exception as e:
logger.fatal("An exception occurred during server startup: %s", e, logger.fatal("An exception occurred during server startup: %s", e,
exc_info=True) exc_info=True)
exit(1) sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -450,7 +450,6 @@ def text_match(vobject_item, filter_, child_name, ns, attrib_name=None):
condition = any(match(child.value) for child in children) condition = any(match(child.value) for child in children)
if filter_.get("negate-condition") == "yes": if filter_.get("negate-condition") == "yes":
return not condition return not condition
else:
return condition return condition
@ -467,9 +466,8 @@ def param_filter_match(vobject_item, filter_, parent_name, ns):
if filter_[0].tag == xmlutils.make_clark("%s:text-match" % ns): if filter_[0].tag == xmlutils.make_clark("%s:text-match" % ns):
return condition and text_match( return condition and text_match(
vobject_item, filter_[0], parent_name, ns, name) vobject_item, filter_[0], parent_name, ns, name)
elif filter_[0].tag == xmlutils.make_clark("%s:is-not-defined" % ns): if filter_[0].tag == xmlutils.make_clark("%s:is-not-defined" % ns):
return not condition return not condition
else:
return condition return condition

View File

@ -77,9 +77,8 @@ class Rights(rights.BaseRights):
collection_pattern, section) collection_pattern, section)
return rights.intersect_permissions( return rights.intersect_permissions(
permissions, rights_config.get(section, "permissions")) permissions, rights_config.get(section, "permissions"))
else:
logger.debug("Rule %r:%r doesn't match %r:%r from section %r", logger.debug("Rule %r:%r doesn't match %r:%r from section %r",
user, sane_path, user_pattern, user, sane_path, user_pattern, collection_pattern,
collection_pattern, section) section)
logger.info("Rights: %r:%r doesn't match any section", user, sane_path) logger.info("Rights: %r:%r doesn't match any section", user, sane_path)
return "" return ""

View File

@ -240,7 +240,7 @@ class BaseCollection:
return (template[:template_insert_pos] + return (template[:template_insert_pos] +
vtimezones + components + vtimezones + components +
template[template_insert_pos:]) template[template_insert_pos:])
elif self.get_meta("tag") == "VADDRESSBOOK": if self.get_meta("tag") == "VADDRESSBOOK":
return "".join((item.serialize() for item in self.get_all())) return "".join((item.serialize() for item in self.get_all()))
return "" return ""

View File

@ -53,7 +53,8 @@ class CollectionCacheMixin:
if modified: if modified:
self._storage._sync_directory(folder) self._storage._sync_directory(folder)
def _item_cache_hash(self, raw_text): @staticmethod
def _item_cache_hash(raw_text):
_hash = sha256() _hash = sha256()
_hash.update(storage.CACHE_VERSION) _hash.update(storage.CACHE_VERSION)
_hash.update(raw_text) _hash.update(raw_text)

View File

@ -84,9 +84,8 @@ class TestBaseAuthRequests(BaseTest):
("😁", "🔑", False), ("😀", "", False), ("😁", "🔑", False), ("😀", "", False),
("", "🔑", False), ("", "", False)) ("", "🔑", False), ("", "", False))
for user, password, valid in test_matrix: for user, password, valid in test_matrix:
status, _ = self.propfind( self.propfind("/", check=207 if valid else 401,
"/", check=207 if valid else 401, HTTP_AUTHORIZATION=( HTTP_AUTHORIZATION=("Basic %s" % base64.b64encode(
"Basic %s" % base64.b64encode(
("%s:%s" % (user, password)).encode()).decode())) ("%s:%s" % (user, password)).encode()).decode()))
def test_htpasswd_plain(self): def test_htpasswd_plain(self):

View File

@ -54,24 +54,23 @@ for short, url in NAMESPACES.items():
ET.register_namespace("" if short == "D" else short, url) ET.register_namespace("" if short == "D" else short, url)
def pretty_xml(element, level=0): def pretty_xml(element):
"""Indent an ElementTree ``element`` and its children.""" """Indent an ElementTree ``element`` and its children."""
if not level: def pretty_xml_recursive(element, level):
element = copy.deepcopy(element) indent = "\n" + level * " "
i = "\n" + level * " "
if len(element) > 0: if len(element) > 0:
if not element.text or not element.text.strip(): if not (element.text or "").strip():
element.text = i + " " element.text = indent + " "
if not element.tail or not element.tail.strip(): if not (element.tail or "").strip():
element.tail = i element.tail = indent
for sub_element in element: for sub_element in element:
pretty_xml(sub_element, level + 1) pretty_xml_recursive(sub_element, level + 1)
if not sub_element.tail or not sub_element.tail.strip(): if not (sub_element.tail or "").strip():
sub_element.tail = i sub_element.tail = indent
else: elif level > 0 and not (element.tail or "").strip():
if level and (not element.tail or not element.tail.strip()): element.tail = indent
element.tail = i element = copy.deepcopy(element)
if not level: pretty_xml_recursive(element, 0)
return '<?xml version="1.0"?>\n%s' % ET.tostring(element, "unicode") return '<?xml version="1.0"?>\n%s' % ET.tostring(element, "unicode")
@ -168,7 +167,7 @@ def props_from_request(xml_request, actions=("set", "remove")):
if resource_type.tag == make_clark("C:calendar"): if resource_type.tag == make_clark("C:calendar"):
result["tag"] = "VCALENDAR" result["tag"] = "VCALENDAR"
break break
elif resource_type.tag == make_clark("CR:addressbook"): if resource_type.tag == make_clark("CR:addressbook"):
result["tag"] = "VADDRESSBOOK" result["tag"] = "VADDRESSBOOK"
break break
elif prop.tag == make_clark("C:supported-calendar-component-set"): elif prop.tag == make_clark("C:supported-calendar-component-set"):