Skip to content

Commit a23a404

Browse files
committed
Add support for icalendar 7.0.0
The following two changes are undocumented in the 7.0.0 release: - Contentlines moved to another module. - Exception raised is now a subclass of ValueError The following is in the changelog: - vcard['N'] now returns structured type vN.
1 parent aa149cd commit a23a404

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ unreleased
1414
* CHANGE the ``pkg_resources`` library is no longer required.
1515
* FIX the location of caching database to ``$XDG_CACHE_HOME``
1616
* FIX color of eventcolumn when editing events in ikhal
17+
* FIX added support for ``icalendar>=7.0.0``.
1718

1819
0.13.0
1920
======

khal/khalendar/backend.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,12 @@ def update_vcf_dates(self, vevent_str: str, href: str, etag: str='',
298298
if 'FN' in vcard:
299299
name = vcard['FN']
300300
else:
301-
n = vcard['N'].split(';')
302-
name = ' '.join([n[1], n[2], n[0]])
301+
vn = vcard['N']
302+
if isinstance (vn, str): # icalendar < 7.0.0
303+
n = vn.split(';')
304+
name = ' '.join([n[1], n[2], n[0]])
305+
else:
306+
name = f'{vn.fields.given} {vn.fields.additional} {vn.fields.family}'
303307
vevent = icalendar.Event()
304308
vevent.add('dtstart', date)
305309
vevent.add('dtend', date + dt.timedelta(days=1))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ requires-python = ">=3.9,<3.14"
2727
dependencies = [
2828
"click>=3.2",
2929
"click_log>=0.2.0",
30-
"icalendar>=6.0.0",
30+
"icalendar>=6.0.0,<8.0.0",
3131
"urwid>=2.6.15",
3232
"pyxdg",
3333
"pytz",

tests/cli_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ def test_print_bad_ics(runner):
507507
runner = runner()
508508
result = runner.invoke(main_khal, ['printics', _get_ics_filepath('non_dst_error')])
509509
assert result.exception
510-
expected = ValueError("Invalid iCalendar duration: PT-2H")
511-
assert expected.__class__ == result.exception.__class__
512-
assert expected.args == result.exception.args
510+
assert isinstance(result.exception, ValueError)
511+
assert str(result.exception) == "Invalid iCalendar duration: PT-2H"
513512

514513
def test_import(runner, monkeypatch):
515514
runner = runner()

tests/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from khal.khalendar import CalendarCollection
88
from khal.khalendar.vdir import Vdir
99

10+
try:
11+
from icalendar.parser import Contentlines # icalendar >= 7.0.0
12+
except ImportError:
13+
from icalendar.cal import Contentlines # icalendar < 7.0.0 # noqa: F401
14+
15+
1016
CollVdirType = tuple[CalendarCollection, dict[str, Vdir]]
1117

1218
cal0 = 'a_calendar'
@@ -75,7 +81,7 @@ def normalize_component(x):
7581
x = icalendar.cal.Component.from_ical(x)
7682

7783
def inner(c):
78-
contentlines = icalendar.cal.Contentlines()
84+
contentlines = Contentlines()
7985
for name, value in c.property_items(sorted=True, recursive=False):
8086
contentlines.append(c.content_line(name, value, sorted=True))
8187
contentlines.append('')

0 commit comments

Comments
 (0)