imip-agent

Changeset

56:b5538d21958b
2014-10-22 Paul Boddie raw files shortlog changelog graph Moved the person handlers to a subpackage.
imip_person.py imiptools/handlers/person.py (file)
     1.1 --- a/imip_person.py	Wed Oct 22 15:41:10 2014 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,192 +0,0 @@
     1.4 -#!/usr/bin/env python
     1.5 -
     1.6 -"""
     1.7 -Handlers for a person for whom scheduling is performed.
     1.8 -"""
     1.9 -
    1.10 -from imiptools.content import Handler
    1.11 -from vCalendar import to_node
    1.12 -
    1.13 -class Event(Handler):
    1.14 -
    1.15 -    "An event handler."
    1.16 -
    1.17 -    def add(self):
    1.18 -        pass
    1.19 -
    1.20 -    def cancel(self):
    1.21 -        pass
    1.22 -
    1.23 -    def counter(self):
    1.24 -
    1.25 -        "Since this handler does not send requests, it will not handle replies."
    1.26 -
    1.27 -        pass
    1.28 -
    1.29 -    def declinecounter(self):
    1.30 -
    1.31 -        """
    1.32 -        Since this handler does not send counter proposals, it will not handle
    1.33 -        replies to such proposals.
    1.34 -        """
    1.35 -
    1.36 -        pass
    1.37 -
    1.38 -    def publish(self):
    1.39 -        pass
    1.40 -
    1.41 -    def refresh(self):
    1.42 -        pass
    1.43 -
    1.44 -    def reply(self):
    1.45 -
    1.46 -        "Since this handler does not send requests, it will not handle replies."
    1.47 -
    1.48 -        pass
    1.49 -
    1.50 -    def request(self):
    1.51 -
    1.52 -        "Hold requests and notify the recipient."
    1.53 -
    1.54 -        oa = self.require_organiser_and_attendees()
    1.55 -        if not oa:
    1.56 -            return None
    1.57 -
    1.58 -        (organiser, organiser_attr), attendees = oa
    1.59 -
    1.60 -        # Process each attendee separately.
    1.61 -
    1.62 -        for attendee, attendee_attr in attendees.items():
    1.63 -
    1.64 -            if not self.have_new_object(attendee, "VEVENT"):
    1.65 -                continue
    1.66 -
    1.67 -            # Store the event and queue the request.
    1.68 -
    1.69 -            self.store.set_event(attendee, self.uid, to_node(
    1.70 -                {"VEVENT" : [(self.details, {})]}
    1.71 -                ))
    1.72 -
    1.73 -            self.store.queue_request(attendee, self.uid)
    1.74 -
    1.75 -        # The message is now wrapped and passed on to the recipient.
    1.76 -
    1.77 -class Freebusy(Handler):
    1.78 -
    1.79 -    "A free/busy handler."
    1.80 -
    1.81 -    def publish(self):
    1.82 -        pass
    1.83 -
    1.84 -    def reply(self):
    1.85 -
    1.86 -        "Since this handler does not send requests, it will not handle replies."
    1.87 -
    1.88 -        pass
    1.89 -
    1.90 -    def request(self):
    1.91 -
    1.92 -        """
    1.93 -        Respond to a request by preparing a reply containing free/busy
    1.94 -        information for each indicated attendee.
    1.95 -        """
    1.96 -
    1.97 -        # NOTE: This is currently the same as the resource handler but should be
    1.98 -        # NOTE: subject to policy/preferences.
    1.99 -
   1.100 -        oa = self.require_organiser_and_attendees()
   1.101 -        if not oa:
   1.102 -            return None
   1.103 -
   1.104 -        (organiser, organiser_attr), attendees = oa
   1.105 -
   1.106 -        # Construct an appropriate fragment.
   1.107 -
   1.108 -        calendar = []
   1.109 -        cwrite = calendar.append
   1.110 -
   1.111 -        # Get the details for each attendee.
   1.112 -
   1.113 -        for attendee, attendee_attr in attendees.items():
   1.114 -            freebusy = self.store.get_freebusy(attendee)
   1.115 -
   1.116 -            if freebusy:
   1.117 -                record = []
   1.118 -                rwrite = record.append
   1.119 -
   1.120 -                rwrite(("ORGANIZER", organiser_attr, organiser))
   1.121 -                rwrite(("ATTENDEE", attendee_attr, attendee))
   1.122 -                rwrite(("UID", {}, self.uid))
   1.123 -
   1.124 -                for start, end, uid in freebusy:
   1.125 -                    rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, [start, end]))
   1.126 -
   1.127 -                cwrite(("VFREEBUSY", {}, record))
   1.128 -
   1.129 -        # Return the reply.
   1.130 -
   1.131 -        return calendar
   1.132 -
   1.133 -class Journal(Handler):
   1.134 -
   1.135 -    "A journal entry handler."
   1.136 -
   1.137 -    def add(self):
   1.138 -        pass
   1.139 -
   1.140 -    def cancel(self):
   1.141 -        pass
   1.142 -
   1.143 -    def publish(self):
   1.144 -        pass
   1.145 -
   1.146 -class Todo(Handler):
   1.147 -
   1.148 -    "A to-do item handler."
   1.149 -
   1.150 -    def add(self):
   1.151 -        pass
   1.152 -
   1.153 -    def cancel(self):
   1.154 -        pass
   1.155 -
   1.156 -    def counter(self):
   1.157 -
   1.158 -        "Since this handler does not send requests, it will not handle replies."
   1.159 -
   1.160 -        pass
   1.161 -
   1.162 -    def declinecounter(self):
   1.163 -
   1.164 -        """
   1.165 -        Since this handler does not send counter proposals, it will not handle
   1.166 -        replies to such proposals.
   1.167 -        """
   1.168 -
   1.169 -        pass
   1.170 -
   1.171 -    def publish(self):
   1.172 -        pass
   1.173 -
   1.174 -    def refresh(self):
   1.175 -        pass
   1.176 -
   1.177 -    def reply(self):
   1.178 -
   1.179 -        "Since this handler does not send requests, it will not handle replies."
   1.180 -
   1.181 -        pass
   1.182 -
   1.183 -    def request(self):
   1.184 -        pass
   1.185 -
   1.186 -# Handler registry.
   1.187 -
   1.188 -handlers = [
   1.189 -    ("VFREEBUSY",   Freebusy),
   1.190 -    ("VEVENT",      Event),
   1.191 -    ("VTODO",       Todo),
   1.192 -    ("VJOURNAL",    Journal),
   1.193 -    ]
   1.194 -
   1.195 -# vim: tabstop=4 expandtab shiftwidth=4
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/imiptools/handlers/person.py	Wed Oct 22 15:42:14 2014 +0200
     2.3 @@ -0,0 +1,192 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +"""
     2.7 +Handlers for a person for whom scheduling is performed.
     2.8 +"""
     2.9 +
    2.10 +from imiptools.content import Handler
    2.11 +from vCalendar import to_node
    2.12 +
    2.13 +class Event(Handler):
    2.14 +
    2.15 +    "An event handler."
    2.16 +
    2.17 +    def add(self):
    2.18 +        pass
    2.19 +
    2.20 +    def cancel(self):
    2.21 +        pass
    2.22 +
    2.23 +    def counter(self):
    2.24 +
    2.25 +        "Since this handler does not send requests, it will not handle replies."
    2.26 +
    2.27 +        pass
    2.28 +
    2.29 +    def declinecounter(self):
    2.30 +
    2.31 +        """
    2.32 +        Since this handler does not send counter proposals, it will not handle
    2.33 +        replies to such proposals.
    2.34 +        """
    2.35 +
    2.36 +        pass
    2.37 +
    2.38 +    def publish(self):
    2.39 +        pass
    2.40 +
    2.41 +    def refresh(self):
    2.42 +        pass
    2.43 +
    2.44 +    def reply(self):
    2.45 +
    2.46 +        "Since this handler does not send requests, it will not handle replies."
    2.47 +
    2.48 +        pass
    2.49 +
    2.50 +    def request(self):
    2.51 +
    2.52 +        "Hold requests and notify the recipient."
    2.53 +
    2.54 +        oa = self.require_organiser_and_attendees()
    2.55 +        if not oa:
    2.56 +            return None
    2.57 +
    2.58 +        (organiser, organiser_attr), attendees = oa
    2.59 +
    2.60 +        # Process each attendee separately.
    2.61 +
    2.62 +        for attendee, attendee_attr in attendees.items():
    2.63 +
    2.64 +            if not self.have_new_object(attendee, "VEVENT"):
    2.65 +                continue
    2.66 +
    2.67 +            # Store the event and queue the request.
    2.68 +
    2.69 +            self.store.set_event(attendee, self.uid, to_node(
    2.70 +                {"VEVENT" : [(self.details, {})]}
    2.71 +                ))
    2.72 +
    2.73 +            self.store.queue_request(attendee, self.uid)
    2.74 +
    2.75 +        # The message is now wrapped and passed on to the recipient.
    2.76 +
    2.77 +class Freebusy(Handler):
    2.78 +
    2.79 +    "A free/busy handler."
    2.80 +
    2.81 +    def publish(self):
    2.82 +        pass
    2.83 +
    2.84 +    def reply(self):
    2.85 +
    2.86 +        "Since this handler does not send requests, it will not handle replies."
    2.87 +
    2.88 +        pass
    2.89 +
    2.90 +    def request(self):
    2.91 +
    2.92 +        """
    2.93 +        Respond to a request by preparing a reply containing free/busy
    2.94 +        information for each indicated attendee.
    2.95 +        """
    2.96 +
    2.97 +        # NOTE: This is currently the same as the resource handler but should be
    2.98 +        # NOTE: subject to policy/preferences.
    2.99 +
   2.100 +        oa = self.require_organiser_and_attendees()
   2.101 +        if not oa:
   2.102 +            return None
   2.103 +
   2.104 +        (organiser, organiser_attr), attendees = oa
   2.105 +
   2.106 +        # Construct an appropriate fragment.
   2.107 +
   2.108 +        calendar = []
   2.109 +        cwrite = calendar.append
   2.110 +
   2.111 +        # Get the details for each attendee.
   2.112 +
   2.113 +        for attendee, attendee_attr in attendees.items():
   2.114 +            freebusy = self.store.get_freebusy(attendee)
   2.115 +
   2.116 +            if freebusy:
   2.117 +                record = []
   2.118 +                rwrite = record.append
   2.119 +
   2.120 +                rwrite(("ORGANIZER", organiser_attr, organiser))
   2.121 +                rwrite(("ATTENDEE", attendee_attr, attendee))
   2.122 +                rwrite(("UID", {}, self.uid))
   2.123 +
   2.124 +                for start, end, uid in freebusy:
   2.125 +                    rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, [start, end]))
   2.126 +
   2.127 +                cwrite(("VFREEBUSY", {}, record))
   2.128 +
   2.129 +        # Return the reply.
   2.130 +
   2.131 +        return calendar
   2.132 +
   2.133 +class Journal(Handler):
   2.134 +
   2.135 +    "A journal entry handler."
   2.136 +
   2.137 +    def add(self):
   2.138 +        pass
   2.139 +
   2.140 +    def cancel(self):
   2.141 +        pass
   2.142 +
   2.143 +    def publish(self):
   2.144 +        pass
   2.145 +
   2.146 +class Todo(Handler):
   2.147 +
   2.148 +    "A to-do item handler."
   2.149 +
   2.150 +    def add(self):
   2.151 +        pass
   2.152 +
   2.153 +    def cancel(self):
   2.154 +        pass
   2.155 +
   2.156 +    def counter(self):
   2.157 +
   2.158 +        "Since this handler does not send requests, it will not handle replies."
   2.159 +
   2.160 +        pass
   2.161 +
   2.162 +    def declinecounter(self):
   2.163 +
   2.164 +        """
   2.165 +        Since this handler does not send counter proposals, it will not handle
   2.166 +        replies to such proposals.
   2.167 +        """
   2.168 +
   2.169 +        pass
   2.170 +
   2.171 +    def publish(self):
   2.172 +        pass
   2.173 +
   2.174 +    def refresh(self):
   2.175 +        pass
   2.176 +
   2.177 +    def reply(self):
   2.178 +
   2.179 +        "Since this handler does not send requests, it will not handle replies."
   2.180 +
   2.181 +        pass
   2.182 +
   2.183 +    def request(self):
   2.184 +        pass
   2.185 +
   2.186 +# Handler registry.
   2.187 +
   2.188 +handlers = [
   2.189 +    ("VFREEBUSY",   Freebusy),
   2.190 +    ("VEVENT",      Event),
   2.191 +    ("VTODO",       Todo),
   2.192 +    ("VJOURNAL",    Journal),
   2.193 +    ]
   2.194 +
   2.195 +# vim: tabstop=4 expandtab shiftwidth=4