1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imiptools/handlers/common.py Tue Nov 25 18:26:30 2014 +0100
1.3 @@ -0,0 +1,58 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Common handler functionality for different entities.
1.8 +"""
1.9 +
1.10 +from imiptools.content import to_part
1.11 +
1.12 +class CommonFreebusy:
1.13 +
1.14 + "Common free/busy mix-in."
1.15 +
1.16 + def request(self):
1.17 +
1.18 + """
1.19 + Respond to a request by preparing a reply containing free/busy
1.20 + information for each indicated attendee.
1.21 + """
1.22 +
1.23 + oa = self.require_organiser_and_attendees()
1.24 + if not oa:
1.25 + return None
1.26 +
1.27 + (organiser, organiser_attr), attendees = organiser_item, attendees = oa
1.28 +
1.29 + # Validate the organiser, ignoring spoofed requests.
1.30 +
1.31 + if not self.validate_identities([organiser_item]):
1.32 + return None
1.33 +
1.34 + # Construct an appropriate fragment.
1.35 +
1.36 + calendar = []
1.37 + cwrite = calendar.append
1.38 +
1.39 + # Get the details for each attendee.
1.40 +
1.41 + for attendee, attendee_attr in attendees.items():
1.42 + freebusy = self.store.get_freebusy(attendee)
1.43 +
1.44 + record = []
1.45 + rwrite = record.append
1.46 +
1.47 + rwrite(("ORGANIZER", organiser_attr, organiser))
1.48 + rwrite(("ATTENDEE", attendee_attr, attendee))
1.49 + rwrite(("UID", {}, self.uid))
1.50 +
1.51 + if freebusy:
1.52 + for start, end, uid in freebusy:
1.53 + rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, [start, end]))
1.54 +
1.55 + cwrite(("VFREEBUSY", {}, record))
1.56 +
1.57 + # Return the reply.
1.58 +
1.59 + return "REPLY", to_part("REPLY", calendar)
1.60 +
1.61 +# vim: tabstop=4 expandtab shiftwidth=4