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:
Markus Unterwaditzer 2014-05-01 15:35:54 +02:00
parent 6e55e6d2c7
commit eb386c8dac
2 changed files with 67 additions and 3 deletions

View file

@ -7,11 +7,61 @@
: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
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'
items = [

View file

@ -16,9 +16,17 @@ USERAGENT = 'vdirsyncer'
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 = []
collection_type = None
item_type = None
timezone = None
for line in text.splitlines():
if u':' not in line:
item.append(line)
@ -30,15 +38,21 @@ def split_collection(text):
elif item_type is None:
item_type = value
item.append(line)
if item_type == u'VTIMEZONE':
timezone = item
else:
item.append(line)
elif key == u'END':
if value == collection_type:
break
elif value == item_type:
if timezone is not None and item_type != u'VTIMEZONE':
item.extend(timezone)
item.append(line)
yield Item(u'\n'.join(item))
if item_type != u'VTIMEZONE':
yield Item(u'\n'.join(item))
item = []
item_type = None
else:
item.append(line)
else: