From 2411b6385202d500a9e57afcbb9abe5b6d1faf1c Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 13 Dec 2025 07:59:02 +0100 Subject: [PATCH 1/5] add function for calculating units for integers --- radicale/utils.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/radicale/utils.py b/radicale/utils.py index 16540bde..eee80c99 100644 --- a/radicale/utils.py +++ b/radicale/utils.py @@ -53,6 +53,15 @@ DATETIME_MAX_UNIXTIME: int = (datetime.MAXYEAR - 1970) * 365 * 24 * 60 * 60 DATETIME_MIN_UNIXTIME: int = (datetime.MINYEAR - 1970) * 365 * 24 * 60 * 60 +# Number units +UNIT_g: int = (1000 * 1000 * 1000) +UNIT_m: int = (1000 * 1000) +UNIT_k: int = (1000) +UNIT_G: int = (1024 * 1024 * 1024) +UNIT_M: int = (1024 * 1024) +UNIT_K: int = (1024) + + def load_plugin(internal_types: Sequence[str], module_name: str, class_name: str, base_class: Type[_T_co], configuration: "config.Configuration") -> _T_co: @@ -294,6 +303,46 @@ def format_ut(unixtime: int) -> str: return r +def format_int(value: int, binary: bool = False) -> str: + if binary: + if value > UNIT_G: + value = value / UNIT_G + unit = "G" + elif value > UNIT_M: + value = value / UNIT_M + unit = "M" + elif value > UNIT_K: + value = value / UNIT_K + unit = "K" + else: + unit = "" + else: + if value > UNIT_g: + value = value / UNIT_g + unit = "g" + elif value > UNIT_m: + value = value / UNIT_m + unit = "m" + elif value > UNIT_k: + value = value / UNIT_k + unit = "k" + else: + unit = "" + return ("%.1f %s" % (value, unit)) + + if unixtime <= DATETIME_MIN_UNIXTIME: + r = str(unixtime) + "(<=MIN:" + str(DATETIME_MIN_UNIXTIME) + ")" + elif unixtime >= DATETIME_MAX_UNIXTIME: + r = str(unixtime) + "(>=MAX:" + str(DATETIME_MAX_UNIXTIME) + ")" + else: + if sys.version_info < (3, 11): + dt = datetime.datetime.utcfromtimestamp(unixtime) + else: + dt = datetime.datetime.fromtimestamp(unixtime, datetime.UTC) + r = str(unixtime) + "(" + dt.strftime('%Y-%m-%dT%H:%M:%SZ') + ")" + return r + + def limit_str(content: str, limit: int) -> str: length = len(content) if limit > 0 and length >= limit: From b8ed32f3ee6030e302d5f3fc1d38a50cb9397006 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 13 Dec 2025 07:59:28 +0100 Subject: [PATCH 2/5] log max-content-length on startup, add formatted int to raw values --- radicale/app/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/radicale/app/__init__.py b/radicale/app/__init__.py index 7d02c2f8..48b7b7f3 100644 --- a/radicale/app/__init__.py +++ b/radicale/app/__init__.py @@ -98,12 +98,13 @@ class Application(ApplicationPartDelete, ApplicationPartHead, self._mask_passwords = configuration.get("logging", "mask_passwords") self._max_content_length = configuration.get("server", "max_content_length") self._max_resource_size = configuration.get("server", "max_resource_size") + logger.info("max_content_length to: %d bytes (%sbytes)", self._max_content_length, utils.format_int(self._max_content_length, binary=True)) if (self._max_resource_size > (self._max_content_length * 0.8)): max_resource_size_limited = int(self._max_content_length * 0.8) - logger.warning("max_resource_size capped to: %d bytes (from %d to 80%% of max_content_length %d)", max_resource_size_limited, self._max_resource_size, self._max_content_length) + logger.warning("max_resource_size capped to: %d bytes (%sbytes) (from %d to 80%% of max_content_length)", max_resource_size_limited, utils.format_int(max_resource_size_limited, binary=True), self._max_resource_size) self._max_resource_size = max_resource_size_limited else: - logger.info("max_resource_size set to: %d bytes", self._max_resource_size) + logger.info("max_resource_size set to: %d bytes (%sbytes)", self._max_resource_size, utils.format_int(self._max_resource_size, binary=True)) self._bad_put_request_content = configuration.get("logging", "bad_put_request_content") logger.info("log bad put request content: %s", self._bad_put_request_content) self._request_header_on_debug = configuration.get("logging", "request_header_on_debug") From 690914e49f86d6b7af029f93621bfbdfe00d182e Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 13 Dec 2025 08:00:06 +0100 Subject: [PATCH 3/5] add unit --- radicale/auth/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/auth/__init__.py b/radicale/auth/__init__.py index 7eadb18a..9114a9f0 100644 --- a/radicale/auth/__init__.py +++ b/radicale/auth/__init__.py @@ -142,7 +142,7 @@ class BaseAuth: if self._lc_username is True and self._uc_username is True: raise RuntimeError("auth.lc_username and auth.uc_username cannot be enabled together") self._auth_delay = configuration.get("auth", "delay") - logger.info("auth.delay: %f", self._auth_delay) + logger.info("auth.delay: %f seconds", self._auth_delay) self._failed_auth_delay = 0 self._lock = threading.Lock() # cache_successful_logins From c73a53d815c91a73d456d9bcf6ae2940afbbb351 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 13 Dec 2025 08:06:44 +0100 Subject: [PATCH 4/5] remove copy-paste overhead --- radicale/utils.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/radicale/utils.py b/radicale/utils.py index eee80c99..14c0f0f3 100644 --- a/radicale/utils.py +++ b/radicale/utils.py @@ -330,18 +330,6 @@ def format_int(value: int, binary: bool = False) -> str: unit = "" return ("%.1f %s" % (value, unit)) - if unixtime <= DATETIME_MIN_UNIXTIME: - r = str(unixtime) + "(<=MIN:" + str(DATETIME_MIN_UNIXTIME) + ")" - elif unixtime >= DATETIME_MAX_UNIXTIME: - r = str(unixtime) + "(>=MAX:" + str(DATETIME_MAX_UNIXTIME) + ")" - else: - if sys.version_info < (3, 11): - dt = datetime.datetime.utcfromtimestamp(unixtime) - else: - dt = datetime.datetime.fromtimestamp(unixtime, datetime.UTC) - r = str(unixtime) + "(" + dt.strftime('%Y-%m-%dT%H:%M:%SZ') + ")" - return r - def limit_str(content: str, limit: int) -> str: length = len(content) From cf98ef0b4aaaaa40a99e0a93cc9a59355acc6041 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 13 Dec 2025 08:06:58 +0100 Subject: [PATCH 5/5] rename function and fix type --- radicale/app/__init__.py | 6 +++--- radicale/utils.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/radicale/app/__init__.py b/radicale/app/__init__.py index 48b7b7f3..4bad79ad 100644 --- a/radicale/app/__init__.py +++ b/radicale/app/__init__.py @@ -98,13 +98,13 @@ class Application(ApplicationPartDelete, ApplicationPartHead, self._mask_passwords = configuration.get("logging", "mask_passwords") self._max_content_length = configuration.get("server", "max_content_length") self._max_resource_size = configuration.get("server", "max_resource_size") - logger.info("max_content_length to: %d bytes (%sbytes)", self._max_content_length, utils.format_int(self._max_content_length, binary=True)) + logger.info("max_content_length set to: %d bytes (%sbytes)", self._max_content_length, utils.format_unit(self._max_content_length, binary=True)) if (self._max_resource_size > (self._max_content_length * 0.8)): max_resource_size_limited = int(self._max_content_length * 0.8) - logger.warning("max_resource_size capped to: %d bytes (%sbytes) (from %d to 80%% of max_content_length)", max_resource_size_limited, utils.format_int(max_resource_size_limited, binary=True), self._max_resource_size) + logger.warning("max_resource_size set to: %d bytes (%sbytes) (capped from %d to 80%% of max_content_length)", max_resource_size_limited, utils.format_unit(max_resource_size_limited, binary=True), self._max_resource_size) self._max_resource_size = max_resource_size_limited else: - logger.info("max_resource_size set to: %d bytes (%sbytes)", self._max_resource_size, utils.format_int(self._max_resource_size, binary=True)) + logger.info("max_resource_size set to: %d bytes (%sbytes)", self._max_resource_size, utils.format_unit(self._max_resource_size, binary=True)) self._bad_put_request_content = configuration.get("logging", "bad_put_request_content") logger.info("log bad put request content: %s", self._bad_put_request_content) self._request_header_on_debug = configuration.get("logging", "request_header_on_debug") diff --git a/radicale/utils.py b/radicale/utils.py index 14c0f0f3..5c0f6c03 100644 --- a/radicale/utils.py +++ b/radicale/utils.py @@ -303,7 +303,7 @@ def format_ut(unixtime: int) -> str: return r -def format_int(value: int, binary: bool = False) -> str: +def format_unit(value: float, binary: bool = False) -> str: if binary: if value > UNIT_G: value = value / UNIT_G