imip-agent

imiptools/handlers/common.py

112:875956967918
2014-11-25 Paul Boddie Preserve the TRANSP property in stored free/busy information. Added a means of retrieving the free/busy information received from others.
     1 #!/usr/bin/env python     2      3 """     4 Common handler functionality for different entities.     5 """     6      7 from imiptools.content import to_part     8      9 class CommonFreebusy:    10     11     "Common free/busy mix-in."    12     13     def request(self):    14     15         """    16         Respond to a request by preparing a reply containing free/busy    17         information for each indicated attendee.    18         """    19     20         oa = self.require_organiser_and_attendees()    21         if not oa:    22             return None    23     24         (organiser, organiser_attr), attendees = organiser_item, attendees = oa    25     26         # Validate the organiser, ignoring spoofed requests.    27     28         if not self.validate_identities([organiser_item]):    29             return None    30     31         # Construct an appropriate fragment.    32     33         calendar = []    34         cwrite = calendar.append    35     36         # Get the details for each attendee.    37     38         for attendee, attendee_attr in attendees.items():    39             freebusy = self.store.get_freebusy(attendee)    40     41             record = []    42             rwrite = record.append    43     44             rwrite(("ORGANIZER", organiser_attr, organiser))    45             rwrite(("ATTENDEE", attendee_attr, attendee))    46             rwrite(("UID", {}, self.uid))    47     48             if freebusy:    49                 for start, end, uid, transp in freebusy:    50                     if transp == "OPAQUE":    51                         rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join([start, end])))    52     53             cwrite(("VFREEBUSY", {}, record))    54     55         # Return the reply.    56     57         return "REPLY", to_part("REPLY", calendar)    58     59 # vim: tabstop=4 expandtab shiftwidth=4