diff --git a/tests/storage/dav/test_main.py b/tests/storage/dav/test_main.py
index 5c22ab5..d041538 100644
--- a/tests/storage/dav/test_main.py
+++ b/tests/storage/dav/test_main.py
@@ -136,7 +136,7 @@ class TestCaldavStorage(DavStorageTests):
('VTODO',),
('VEVENT',),
('VTODO', 'VEVENT'),
- ('VTODO', 'VEVENT', 'VJOURNAL'),
+ ('VTODO', 'VEVENT', 'VJOURNAL')
])
def test_item_types_performance(self, item_types, monkeypatch):
kw = self.get_storage_args()
diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py
index 1867d48..91fdeab 100644
--- a/vdirsyncer/storage/dav.py
+++ b/vdirsyncer/storage/dav.py
@@ -283,14 +283,16 @@ class CaldavStorage(DavStorage):
get_multi_data_query = '{urn:ietf:params:xml:ns:caldav}calendar-data'
def __init__(self, start_date=None, end_date=None,
- item_types=('VTODO', 'VEVENT'), **kwargs):
+ item_types=(), **kwargs):
'''
:param start_date: Start date of timerange to show, default -inf.
:param end_date: End date of timerange to show, default +inf.
- :param item_types: The item types to show from the server. Dependent on
- server functionality, no clientside validation of results. This
- currently only affects the `list` method, but this shouldn't cause
- problems in the normal usecase.
+ :param item_types: A tuple of collection types to show from the server.
+ For example, if you want to only get VEVENTs, pass ``('VEVENT',)``.
+ Falsy values mean "get all types". Dependent on server
+ functionality, no clientside validation of results. This currently
+ only affects the `list` method, but this shouldn't cause problems
+ in the normal usecase.
'''
super(CaldavStorage, self).__init__(**kwargs)
if isinstance(item_types, str):
@@ -308,9 +310,34 @@ class CaldavStorage(DavStorage):
(eval(end_date, namespace) if isinstance(end_date, str)
else end_date)
- self._list_template = self._get_list_template()
+ @staticmethod
+ def _get_list_filters(components, start, end):
- def _get_list_template(self):
+ if not components:
+ components = ('VTODO', 'VEVENT')
+
+ caldavfilter = '''
+
+
+ {timefilter}
+
+
+ '''
+
+ if start is not None and end is not None:
+ start = start.strftime(CALDAV_DT_FORMAT)
+ end = end.strftime(CALDAV_DT_FORMAT)
+
+ timefilter = (''
+ .format(start=start, end=end))
+ else:
+ timefilter = ''
+
+ for component in components:
+ yield caldavfilter.format(component=component,
+ timefilter=timefilter)
+
+ def list(self):
data = '''
@@ -318,27 +345,17 @@ class CaldavStorage(DavStorage):
-
-
- {caldavfilter}
-
-
+ {caldavfilter}
'''
- start = self.start_date
- end = self.end_date
- caldavfilter = ''
- if start is not None and end is not None:
- start = start.strftime(CALDAV_DT_FORMAT)
- end = end.strftime(CALDAV_DT_FORMAT)
- caldavfilter = (''
- .format(start=start, end=end))
- return data.format(caldavfilter=caldavfilter, component='{item_type}')
- def list(self):
hrefs = set()
- for t in self.item_types:
- xml = self._list_template.format(item_type=t)
+
+ caldavfilters = self._get_list_filters(self.item_types,
+ self.start_date, self.end_date)
+
+ for caldavfilter in caldavfilters:
+ xml = data.format(caldavfilter=caldavfilter)
for href, etag in self._list(xml):
assert href not in hrefs
hrefs.add(href)