Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions caldav/lib/vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,29 @@ def fix(event):
if fixed2 != event:
global fixup_error_loggings
fixup_error_loggings += 1
remove_bit = lambda n: n & (n - 1)
if not remove_bit(fixup_error_loggings):
log = logging.error
is_power_of_two = lambda n: not (n & (n - 1))
if is_power_of_two(fixup_error_loggings):
log = logging.warning
else:
log = logging.debug
log(
"""Ical data was modified to avoid compatibility issues
(Your calendar server breaks the icalendar standard)
This is probably harmless, particularly if not editing events or tasks
(error count: %i - this error is ratelimited)"""
% fixup_error_loggings,
exc_info=True,
)

log_message = [
"Ical data was modified to avoid compatibility issues",
"(Your calendar server breaks the icalendar standard)",
"This is probably harmless, particularly if not editing events or tasks",
f"(error count: {fixup_error_loggings} - this error is ratelimited)",
]

try:
import difflib

log(
"\n".join(
difflib.unified_diff(
event.split("\n"), fixed2.split("\n"), lineterm=""
)
)
diff = list(
difflib.unified_diff(event.split("\n"), fixed2.split("\n"), lineterm="")
)
except:
log("Original: \n" + event)
log("Modified: \n" + fixed2)
diff = ["Original: ", event, "Modified: ", fixed2]

log("\n".join(log_message + diff))

return fixed2

Expand Down