# Setup import vobject import datetime # This part works fine cal=vobject.iCalendar() cal.add('vevent').add('dtstart').value = datetime.datetime(2010,3,15,20) cal.vevent.add('rrule').value="FREQ=WEEKLY" print "Same content for every test:" cal.prettyPrint() print "You can access rruleset from the event in the calendar:" incidence_list = list(cal.vevent.rruleset[0:2]) print "about to print the first incidence_list:" print incidence_list print "" # This part works too (because vevent_p is just a reference to a vevent inside # an icalendar object?) print "And you can access rruleset from a reference to the vevent object in the calendar:" event_object = cal.vevent event_object.prettyPrint() incidence_list2 = list(event_object.rruleset[0:2]) print "about to print the second incidence_list:" print incidence_list2 print "" print "But, you can't access rruleset from a standalone vevent object. Why?" new_ev_object = vobject.newFromBehavior('vevent') new_ev_object.add('dtstart').value = datetime.datetime(2010,3,15,20) new_ev_object.add('rrule').value="FREQ=WEEKLY" new_ev_object.prettyPrint() print "About to attempt accessing the standalone object's " print "rruleset. This will fail." try: incidence_list3 = list(new_ev_object.rruleset[0:2]) except AttributeError: print "Caught an AttributeError b/c standalone vevent objects don't have a rruleset attribute" print "Add the vevent object to the calendar, it appears the same:" cal2 = vobject.iCalendar() cal2.add(new_ev_object) # Now the event is part of the calendar. cal2.prettyPrint() print "But, it doesn't work like the other vevent + vcalendar object I made:" try: incidence_list4 = list(cal2.vevent.rruleset[0:2]) except AttributeError: print "Caught an AttributeError b/c standalone vevent objects" print " later added to an iCal don't have a rruleset attribute" print "But clearly all the information is there, because if I " print "serialize and parse the broken iCal object, it works again!" parsedCal = vobject.readOne(cal2.serialize()) parsedCal.prettyPrint() incidence_list5 = parsedCal.vevent.rruleset[0:2] print "about to print incidence list 5:" print "" print incidence_list5 print "" print "thanks for reading!"