python-caldav / caldav

Apache License 2.0
326 stars 98 forks source link

various fixes, improved reliability #224

Closed tobixen closed 2 years ago

tobixen commented 2 years ago

Most objects returned from the caldav server has one vcalendar with one subcomponent, which may be an Event, Todo, Journal or FreeBusy from the icalendar library. However, some calendar servers may also return a Timezone subcomponent. (and in addition, when there are recurrences involved, an object may have multiple recurrences given as subcomponents).

It seems like I've encountered this before and created an object._icalendar_object which looks through the subcomponents and return the first relevant subcomponent found - but then forgotten about this method, and creating code just asserting that the data we're looking for is available as self.icalendar_instance.subcomponents[0].

With this pull request, I'm removing the first underscore from the said method to indicate that it's a public method, the method has been rewritten to call on assert_ if unexpected things happen, and I'm using this method rather than subcomponents[0]

While working on this I stumbled upon some other potential bugs;

Another en-passant thing, "import icalendar" has been moved to the top of the file.