mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
TIMEZONE issue
Some URLs such as https://mozorg.cdn.mozilla.net/media/caldata/JapanHolidays.ics have VTIMEZONES at the top.
This commit is contained in:
parent
6e55e6d2c7
commit
eb386c8dac
2 changed files with 67 additions and 3 deletions
|
|
@ -7,11 +7,61 @@
|
||||||
:license: MIT, see LICENSE for more details.
|
:license: MIT, see LICENSE for more details.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from vdirsyncer.storage.http import HttpStorage
|
from vdirsyncer.storage.http import HttpStorage, split_collection
|
||||||
from requests import Response
|
from requests import Response
|
||||||
|
|
||||||
|
|
||||||
def test_list(self, monkeypatch):
|
def test_split_collection_timezones():
|
||||||
|
items = [
|
||||||
|
(
|
||||||
|
u'BEGIN:VEVENT',
|
||||||
|
u'SUMMARY:Eine Kurzinfo',
|
||||||
|
u'DESCRIPTION:Beschreibung des Termines',
|
||||||
|
u'END:VEVENT'
|
||||||
|
),
|
||||||
|
(
|
||||||
|
u'BEGIN:VEVENT',
|
||||||
|
u'SUMMARY:Eine zweite Kurzinfo',
|
||||||
|
u'DESCRIPTION:Beschreibung des anderen Termines',
|
||||||
|
u' With an extra line for description',
|
||||||
|
u'BEGIN:VALARM',
|
||||||
|
u'ACTION:AUDIO',
|
||||||
|
u'TRIGGER:19980403T120000',
|
||||||
|
u'ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud',
|
||||||
|
u'REPEAT:4',
|
||||||
|
u'DURATION:PT1H',
|
||||||
|
u'END:VALARM',
|
||||||
|
u'END:VEVENT'
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
timezone = (
|
||||||
|
u'BEGIN:VTIMEZONE',
|
||||||
|
u'TZID:/mozilla.org/20070129_1/Asia/Tokyo',
|
||||||
|
u'X-LIC-LOCATION:Asia/Tokyo',
|
||||||
|
u'BEGIN:STANDARD',
|
||||||
|
u'TZOFFSETFROM:+0900',
|
||||||
|
u'TZOFFSETTO:+0900',
|
||||||
|
u'TZNAME:JST',
|
||||||
|
u'DTSTART:19700101T000000',
|
||||||
|
u'END:STANDARD',
|
||||||
|
u'END:VTIMEZONE'
|
||||||
|
)
|
||||||
|
|
||||||
|
full = u'\n'.join(
|
||||||
|
(u'BEGIN:VCALENDAR',) +
|
||||||
|
timezone + tuple(line for item in items for line in item) +
|
||||||
|
(u'END:VCALENDAR',)
|
||||||
|
)
|
||||||
|
|
||||||
|
given = [tuple(x.raw.splitlines()) for x in split_collection(full)]
|
||||||
|
expected = [item[:-1] + timezone + (item[-1],) for item in items]
|
||||||
|
print(given)
|
||||||
|
print(expected)
|
||||||
|
assert given == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_list(monkeypatch):
|
||||||
collection_url = 'http://127.0.0.1/calendar/collection.ics'
|
collection_url = 'http://127.0.0.1/calendar/collection.ics'
|
||||||
|
|
||||||
items = [
|
items = [
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,17 @@ USERAGENT = 'vdirsyncer'
|
||||||
|
|
||||||
|
|
||||||
def split_collection(text):
|
def split_collection(text):
|
||||||
|
'''
|
||||||
|
This is a horrible "parser", but Python tooling isn't much better. The only
|
||||||
|
library which supports both calendars and addressbooks (VObject) is Python
|
||||||
|
2 only and doesn't seem maintained anymore, the other one (icalendar) only
|
||||||
|
handles calendars... which wouldn't eliminate this function anyway. Let's
|
||||||
|
just hope this handles all cases.
|
||||||
|
'''
|
||||||
item = []
|
item = []
|
||||||
collection_type = None
|
collection_type = None
|
||||||
item_type = None
|
item_type = None
|
||||||
|
timezone = None
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
if u':' not in line:
|
if u':' not in line:
|
||||||
item.append(line)
|
item.append(line)
|
||||||
|
|
@ -30,15 +38,21 @@ def split_collection(text):
|
||||||
elif item_type is None:
|
elif item_type is None:
|
||||||
item_type = value
|
item_type = value
|
||||||
item.append(line)
|
item.append(line)
|
||||||
|
if item_type == u'VTIMEZONE':
|
||||||
|
timezone = item
|
||||||
else:
|
else:
|
||||||
item.append(line)
|
item.append(line)
|
||||||
elif key == u'END':
|
elif key == u'END':
|
||||||
if value == collection_type:
|
if value == collection_type:
|
||||||
break
|
break
|
||||||
elif value == item_type:
|
elif value == item_type:
|
||||||
|
if timezone is not None and item_type != u'VTIMEZONE':
|
||||||
|
item.extend(timezone)
|
||||||
item.append(line)
|
item.append(line)
|
||||||
|
if item_type != u'VTIMEZONE':
|
||||||
yield Item(u'\n'.join(item))
|
yield Item(u'\n'.join(item))
|
||||||
item = []
|
item = []
|
||||||
|
item_type = None
|
||||||
else:
|
else:
|
||||||
item.append(line)
|
item.append(line)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue