Code Repositories xandikos / 2bd4cd4
Skip non-calendar files from CalendarQueryFilter. Fixes #108 Jelmer Vernooij 23 days ago
4 changed file(s) with 17 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
11
22 * Fix <calendar-data> subelement filtering. (Jelmer Vernooij)
33
4 * Skip non-calendar files for calendar-query operations.
5 (Jelmer Vernooij, #108)
6
47 0.1.0 2019-04-07
58
69 Initial release.
690690 class CalendarFilter(Filter):
691691 """A filter that works on ICalendar files."""
692692
693 content_type = 'text/calendar'
694
693695 def __init__(self, default_timezone):
694696 self.tzify = lambda dt: as_tz_aware_ts(dt, default_timezone)
695697 self.children = []
702704 return ret
703705
704706 def check(self, name, file):
705 if file.content_type != 'text/calendar':
706 return False
707707 c = file.calendar
708708 if c is None:
709709 return False
127127 Filters are often resource-type specific.
128128 """
129129
130 content_type = None
131
130132 def check(self, name, resource):
131133 """Check if this filter applies to a resource.
132134
259261
260262 def _iter_with_filter_naive(self, filter):
261263 for (name, content_type, etag) in self.iter_with_etag():
264 if not filter.content_type == content_type:
265 continue
262266 file = self.get_file(name, content_type, etag)
263267 if filter.check(name, file):
264268 yield (name, file, etag)
265269
266270 def _iter_with_filter_indexes(self, filter, keys):
267271 for (name, content_type, etag) in self.iter_with_etag():
272 if not filter.content_type == content_type:
273 continue
268274 try:
269275 file_values = self.index.get_values(name, etag, keys)
270276 except KeyError:
128128
129129 class DummyFilter(Filter):
130130
131 content_type = 'text/calendar'
132
131133 def __init__(self, text):
132134 self.text = text
133135
134136 def check(self, name, resource):
135 if resource.content_type != 'text/calendar':
136 return False
137137 return self.text in b''.join(resource.content)
138138
139139 self.assertEqual(
155155 [EXAMPLE_VCALENDAR1])
156156 (name2, etag2) = gc.import_one('bar.ics', 'text/calendar',
157157 [EXAMPLE_VCALENDAR2])
158 (name3, etag3) = gc.import_one('bar.txt', 'text/plain',
159 [b'Not a calendar file.'])
158160 self.assertEqual({}, dict(gc.index_manager.desired))
159161
160162 filtertext = 'C=VCALENDAR/C=VTODO/P=SUMMARY'
161163
162164 class DummyFilter(Filter):
165
166 content_type = 'text/calendar'
163167
164168 def __init__(self, text):
165169 self.text = text
172176 for v in index_values[filtertext])
173177
174178 def check(self, name, resource):
175 if resource.content_type != 'text/calendar':
176 return False
177179 return self.text in b''.join(resource.content)
178180
179181 self.assertEqual(