python-caldav / caldav

Apache License 2.0
317 stars 94 forks source link

The new `event.icalendar_component` property needs doc and example code #239

Open tobixen opened 1 year ago

tobixen commented 1 year ago

An event, journal or todo object in the caldav library contains an iCalendar object. An iCalendar object may be a collection of components (that is, events, tasks and/or journals ... plus timezone). The caldav objects typically contains only one component. The notable exception is with recurrence sets (either an expanded recurring event/task/object or with a recurring event/task/object containing exceptions or edited instances). That should be the only exception. For use-cases where one does not need to care about recurrence sets, quite often one wants to be able to access the component and not the iCalendar object.

The methods data (and wire_data), vobject_instance and icalendar_instance for accessing the object as either a string (bytestring), a vobject instance or an icalendar instance. The icalendar library seems to be more popular than the vobject, so I'm slowly moving to using icalendar internally.

To get the component through the data one may strip out the first and last line, containing BEGIN:VCALENDAR and END:VCALENDAR. To get it through the vobject one may access it as event.vobject_instance.vevent - but that fails if the object is a vtodo or vjournal. To get it through icalendar, one could try to do event.icalendar_instance.subcomponents[0] - however, that would give compatibility problems as some servers yields a timezone as the first subcomponent.

In #232 I made a new property event.icalendar_component which returns the component rather than the whole icalendar object. It's useful, and already used internally many places. However, it lacks example code and documentation. It's needed to look through the examples, see if it may be useful to replace some of the current code with the icalendar_component property, or eventually to add some new code that is utilizing the icalendar_component property.