# HG changeset patch # User Paul Boddie # Date 1411680081 -7200 # Node ID 01eb9de3415e7fd77db5799e29a8f92d8ebca7ae # Parent c38609e4aef22fb1fb9cfa4d86fc131f13117c4b Introduced explicit VALUE attribute handling for dates and datetimes. Added FBTYPE attributes to FREEBUSY properties. Introduced support for TRANSP properties. diff -r c38609e4aef2 -r 01eb9de3415e imip_agent.py --- a/imip_agent.py Wed Sep 24 16:48:32 2014 +0200 +++ b/imip_agent.py Thu Sep 25 23:21:21 2014 +0200 @@ -86,7 +86,9 @@ def get_utc_datetime(d, name): value, attr = get_item(d, name) dt = get_datetime(value, attr) - if isinstance(dt, datetime): + if not dt: + return None + elif isinstance(dt, datetime): return dt.astimezone(timezone("UTC")).strftime("%Y%m%dT%H%M%SZ") else: return dt.strftime("%Y%m%d") @@ -103,27 +105,29 @@ except UnknownTimeZoneError: tz = None - m = match_datetime_icalendar(value) - if m: - dt = datetime( - int(m.group("year")), int(m.group("month")), int(m.group("day")), - int(m.group("hour")), int(m.group("minute")), int(m.group("second")) - ) + if attr.get("VALUE") in (None, "DATE-TIME"): + m = match_datetime_icalendar(value) + if m: + dt = datetime( + int(m.group("year")), int(m.group("month")), int(m.group("day")), + int(m.group("hour")), int(m.group("minute")), int(m.group("second")) + ) - # Impose the indicated timezone. - # NOTE: This needs an ambiguity policy for DST changes. + # Impose the indicated timezone. + # NOTE: This needs an ambiguity policy for DST changes. - tz = m.group("utc") and timezone("UTC") or tz or None - if tz is not None: - return tz.localize(dt) - else: - return dt + tz = m.group("utc") and timezone("UTC") or tz or None + if tz is not None: + return tz.localize(dt) + else: + return dt - m = match_date_icalendar(value) - if m: - return date( - int(m.group("year")), int(m.group("month")), int(m.group("day")) - ) + if attr.get("VALUE") == "DATE": + m = match_date_icalendar(value) + if m: + return date( + int(m.group("year")), int(m.group("month")), int(m.group("day")) + ) return None # Time management. @@ -445,7 +449,10 @@ if not conflict: insert_period(freebusy, (dtstart, dtend, self.uid)) - self.store.set_freebusy(attendee, freebusy) + + if self.get_value("TRANSP") in (None, "TRANSPARENT"): + self.store.set_freebusy(attendee, freebusy) + self.store.set_event(attendee, self.uid, to_node( {"VEVENT" : [(self.details, {})]} )) @@ -510,7 +517,7 @@ rwrite(("UID", {}, self.uid)) for start, end, uid in freebusy: - rwrite(("FREEBUSY", {}, [start, end])) + rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, [start, end])) cwrite(("VFREEBUSY", {}, record))