Code Repositories xandikos / bb87de3
Add detail string to InvalidFileContent Jelmer Vernooń≥ 4 months ago
3 changed file(s) with 15 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
3535 """Validate a calendar object.
3636
3737 :param cal: Calendar object
38 :return: iterator over error messages
3839 """
3940 for error in validate_component(cal, strict=strict):
4041 yield error
209210 cal = self.calendar
210211 # TODO(jelmer): return the list of errors to the caller
211212 if cal.is_broken:
212 raise InvalidFileContents(self.content_type, self.content)
213 if list(validate_calendar(cal, strict=False)):
214 raise InvalidFileContents(self.content_type, self.content)
213 raise InvalidFileContents(self.content_type, self.content,
214 "Broken calendar file")
215 errors = list(validate_calendar(cal, strict=False))
216 if errors:
217 raise InvalidFileContents(
218 self.content_type, self.content,
219 ", ".join(errors))
215220
216221 def normalized(self):
217222 """Return a normalized version of the file."""
222227 if self._calendar is None:
223228 try:
224229 self._calendar = Calendar.from_ical(b''.join(self.content))
225 except ValueError:
226 raise InvalidFileContents(self.content_type, self.content)
230 except ValueError as e:
231 raise InvalidFileContents(
232 self.content_type, self.content, str(e))
227233 return self._calendar
228234
229235 def describe_delta(self, name, previous):
158158 class InvalidFileContents(Exception):
159159 """Invalid file contents."""
160160
161 def __init__(self, content_type, data):
161 def __init__(self, content_type, data, error):
162162 self.content_type = content_type
163163 self.data = data
164 self.error = error
164165
165166
166167 class Store(object):
3030 c = b''.join(self.content).strip()
3131 if not c.startswith((b'BEGIN:VCARD\r\n', b'BEGIN:VCARD\n')) or \
3232 not c.endswith(b'\nEND:VCARD'):
33 raise InvalidFileContents(self.content_type, self.content)
33 raise InvalidFileContents(self.content_type, self.content,
34 "Missing header and trailer lines")