Cosmetic changes
This commit is contained in:
parent
fc180266d5
commit
db7587c593
@ -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__":
|
||||||
|
@ -450,8 +450,7 @@ 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
|
|
||||||
|
|
||||||
|
|
||||||
def param_filter_match(vobject_item, filter_, parent_name, ns):
|
def param_filter_match(vobject_item, filter_, parent_name, ns):
|
||||||
@ -467,10 +466,9 @@ 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
|
|
||||||
|
|
||||||
|
|
||||||
def simplify_prefilters(filters, collection_tag="VCALENDAR"):
|
def simplify_prefilters(filters, collection_tag="VCALENDAR"):
|
||||||
|
@ -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, collection_pattern,
|
||||||
user, sane_path, user_pattern,
|
section)
|
||||||
collection_pattern, 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 ""
|
||||||
|
@ -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 ""
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -84,10 +84,9 @@ 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):
|
||||||
self._test_htpasswd("plain", "tmp:bepo")
|
self._test_htpasswd("plain", "tmp:bepo")
|
||||||
|
@ -54,25 +54,24 @@ 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 "").strip():
|
||||||
if not element.text or not element.text.strip():
|
element.text = indent + " "
|
||||||
element.text = i + " "
|
if not (element.tail or "").strip():
|
||||||
if not element.tail or not element.tail.strip():
|
element.tail = indent
|
||||||
element.tail = i
|
for sub_element in element:
|
||||||
for sub_element in element:
|
pretty_xml_recursive(sub_element, level + 1)
|
||||||
pretty_xml(sub_element, level + 1)
|
if not (sub_element.tail or "").strip():
|
||||||
if not sub_element.tail or not sub_element.tail.strip():
|
sub_element.tail = indent
|
||||||
sub_element.tail = i
|
elif level > 0 and not (element.tail or "").strip():
|
||||||
else:
|
element.tail = indent
|
||||||
if level and (not element.tail or not element.tail.strip()):
|
element = copy.deepcopy(element)
|
||||||
element.tail = i
|
pretty_xml_recursive(element, 0)
|
||||||
if not level:
|
return '<?xml version="1.0"?>\n%s' % ET.tostring(element, "unicode")
|
||||||
return '<?xml version="1.0"?>\n%s' % ET.tostring(element, "unicode")
|
|
||||||
|
|
||||||
|
|
||||||
def make_clark(human_tag):
|
def make_clark(human_tag):
|
||||||
@ -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"):
|
||||||
|
Loading…
Reference in New Issue
Block a user