From gcash at cfl.rr.com Tue Oct 9 00:34:07 2007 From: gcash at cfl.rr.com (Gene Cash) Date: Mon, 08 Oct 2007 18:34:07 -0400 Subject: [icalendar-dev] problem pickling event instances (with patch!) Message-ID: <470AB05F.1080703@cfl.rr.com> It turns out if you try picking event instances, you get: cPickle.PicklingError: Can't pickle : it's not the same object as icalendar.prop.UTC This is because of line 228 in prop.py, which turns the UTC class into an instance, thus confusing pickle. The simple fix is to simply rename the class: --- prop.py.orig 2007-10-08 18:21:07.000000000 -0400 +++ prop.py 2007-10-08 18:11:57.000000000 -0400 @@ -211,24 +211,24 @@ return self.__name def dst(self, dt): return ZERO -class UTC(tzinfo): +class UTC_class(tzinfo): """UTC tzinfo subclass""" def utcoffset(self, dt): return ZERO def tzname(self, dt): return "UTC" def dst(self, dt): return ZERO -UTC = UTC() +UTC = UTC_class() class LocalTimezone(tzinfo): """ Timezone of the machine where the code is running """ I can't see this breaking anything. I'm using Python 2.5.1 I'm writing a calendar app for my Nokia N800 (see http://home.cfl.rr.com/genecash/nokia/index.html) Event objects are nifty and useful, so after I import an iCal file I'm using a dictionary of events keyed by GUID as part of my internal calender representation. It makes "syncing" to multiple sources of calendar info easier. I have at least 3 brain-dead scheduling apps I must use daily, but at least all of them can speak RFC 2445, so this is important. It's still pre-alpha but you might want to look at the code. Thanks for writing a really nice piece of software. Well done. -gc -- Is this my glass? Is it? Does it *look* like my glass? No. *My* glass was bigger. And full. From gcash at cfl.rr.com Wed Oct 10 02:25:20 2007 From: gcash at cfl.rr.com (Gene Cash) Date: Tue, 09 Oct 2007 20:25:20 -0400 Subject: [icalendar-dev] problem with negative fractional vDuration (with patch) Message-ID: <470C1BF0.1000604@cfl.rr.com> It seems that vDuration objects have a problem with negative fractional days. I first noticed this when I was dealing with VALARMs. >>> import icalendar >>> s='''BEGIN:VALARM ... ACTION:DISPLAY ... DESCRIPTION:Testing ... TRIGGER:-PT5M ... END:VALARM''' >>> >>> cal=icalendar.Calendar.from_string(s) >>> alarm=cal.walk('VALARM')[0] >>> print alarm BEGIN:VALARM ACTION:DISPLAY DESCRIPTION:Testing TRIGGER:-P1DT23H55M END:VALARM Note the incorrect trigger value. >>> print alarm.decoded('TRIGGER') -2 days, 0:05:00 >>> x=icalendar.vDuration.from_ical('-PT10M') >>> icalendar.vDuration(x).ical() '-P1DT23H50M' Oops. It turns out that negative datetime.timedeltas get normalized, so that datetime.timedelta(minutes=-5) becomes datetime.timedelta(-1, 86100) which actually means -1 day, +23 hours, +55 minutes, which is where the "TRIGGER:-P1DT23H55M" comes from. This upsets vDuration. The fix is a one-liner in the vDuration.ical method: --- prop.py.new 2007-10-09 20:17:11.000000000 -0400 +++ prop.py 2007-10-09 20:17:18.000000000 -0400 @@ -423,12 +423,13 @@ self.params = Parameters() def ical(self): sign = "" if self.td.days < 0: sign = "-" + self.td=-self.td timepart = "" if self.td.seconds: timepart = "T" hours = self.td.seconds // 3600 minutes = self.td.seconds % 3600 // 60 seconds = self.td.seconds % 60 After this, things work: >>> import icalendar >>> s='''BEGIN:VALARM ... ACTION:DISPLAY ... DESCRIPTION:Testing ... TRIGGER:-PT5M ... END:VALARM''' >>> >>> cal=icalendar.Calendar.from_string(s) >>> alarm=cal.walk('VALARM')[0] >>> print alarm BEGIN:VALARM ACTION:DISPLAY DESCRIPTION:Testing TRIGGER:-PT5M END:VALARM >>> print alarm.decoded('TRIGGER') -1 day, 23:55:00 >>> x=icalendar.vDuration.from_ical('-PT10M') >>> icalendar.vDuration(x).ical() '-PT10M' Yay. That was not easy to figure out. -gc -- Is this my glass? Is it? Does it *look* like my glass? No. *My* glass was bigger. And full.