[CalendarServer-changes] [14301] PyCalendar/trunk/src/pycalendar

source_changes at macosforge.org source_changes at macosforge.org
Wed Jan 14 07:39:56 PST 2015


Revision: 14301
          http://trac.calendarserver.org//changeset/14301
Author:   cdaboo at apple.com
Date:     2015-01-14 07:39:56 -0800 (Wed, 14 Jan 2015)
Log Message:
-----------
Update to latest VPOLL spec.

Modified Paths:
--------------
    PyCalendar/trunk/src/pycalendar/__init__.py
    PyCalendar/trunk/src/pycalendar/icalendar/definitions.py
    PyCalendar/trunk/src/pycalendar/icalendar/property.py
    PyCalendar/trunk/src/pycalendar/icalendar/tests/test_vpoll.py
    PyCalendar/trunk/src/pycalendar/icalendar/vpoll.py

Added Paths:
-----------
    PyCalendar/trunk/src/pycalendar/icalendar/vote.py
    PyCalendar/trunk/src/pycalendar/icalendar/vvoter.py

Modified: PyCalendar/trunk/src/pycalendar/__init__.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/__init__.py	2015-01-14 15:38:08 UTC (rev 14300)
+++ PyCalendar/trunk/src/pycalendar/__init__.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -1,5 +1,5 @@
 ##
-#    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
+#    Copyright (c) 2007-2015 Cyrus Daboo. All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License");
 #    you may not use this file except in compliance with the License.
@@ -44,8 +44,10 @@
 import icalendar.vfreebusy
 import icalendar.vjournal
 import icalendar.vpoll
+import icalendar.vote
 import icalendar.vtimezone
 import icalendar.vtimezonedaylight
 import icalendar.vtimezonestandard
 import icalendar.vtodo
 import icalendar.vunknown
+import icalendar.vvoter

Modified: PyCalendar/trunk/src/pycalendar/icalendar/definitions.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/definitions.py	2015-01-14 15:38:08 UTC (rev 14300)
+++ PyCalendar/trunk/src/pycalendar/icalendar/definitions.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -1,5 +1,5 @@
 ##
-#    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
+#    Copyright (c) 2007-2015 Cyrus Daboo. All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License");
 #    you may not use this file except in compliance with the License.
@@ -334,24 +334,27 @@
 cICalProperty_ACTION_NONE = "NONE"
 
 
-#    Extensions: draft-york-vpoll-00.txt
+#    Extensions: draft-york-vpoll-03.txt
 
-#    Section 4.1
-cICalParamater_PUBLIC_COMMENT = "PUBLIC-COMMENT"
-cICalParamater_RESPONSE = "RESPONSE"
+#    Section 4.3
+cICalParamater_REQUIRED = "REQUIRED"
 cICalParamater_STAY_INFORMED = "STAY-INFORMED"
 
-#    Section 4.2
+#    Section 4.4
 cICalProperty_ACCEPT_RESPONSE = "ACCEPT-RESPONSE"
+cICalProperty_POLL_COMPLETION = "POLL-COMPLETION"
 cICalProperty_POLL_ITEM_ID = "POLL-ITEM-ID"
-cICalProperty_POLL_WINNER = "POLL-WINNER"
 cICalProperty_POLL_MODE = "POLL-MODE"
 cICalProperty_POLL_MODE_BASIC = "BASIC"
 cICalProperty_POLL_PROPERTIES = "POLL-PROPERTIES"
+cICalProperty_POLL_WINNER = "POLL-WINNER"
+cICalProperty_RESPONSE = "RESPONSE"
 cICalProperty_VOTER = "VOTER"
 
-#    Section 4.3
+#    Section 4.5
 cICalComponent_VPOLL = "VPOLL"
+cICalComponent_VVOTER = "VVOTER"
+cICalComponent_VOTE = "VOTE"
 
 
 #     Mulberry extensions

Modified: PyCalendar/trunk/src/pycalendar/icalendar/property.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/property.py	2015-01-14 15:38:08 UTC (rev 14300)
+++ PyCalendar/trunk/src/pycalendar/icalendar/property.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -1,5 +1,5 @@
 ##
-#    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
+#    Copyright (c) 2007-2015 Cyrus Daboo. All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License");
 #    you may not use this file except in compliance with the License.
@@ -105,10 +105,12 @@
         # Extensions: draft-york-vpoll-00.txt
         # Section 4.2
         definitions.cICalProperty_ACCEPT_RESPONSE   : Value.VALUETYPE_TEXT,
-        definitions.cICalProperty_POLL_ITEM_ID      : Value.VALUETYPE_TEXT,
-        definitions.cICalProperty_POLL_WINNER       : Value.VALUETYPE_TEXT,
+        definitions.cICalProperty_POLL_COMPLETION   : Value.VALUETYPE_TEXT,
+        definitions.cICalProperty_POLL_ITEM_ID      : Value.VALUETYPE_INTEGER,
         definitions.cICalProperty_POLL_MODE         : Value.VALUETYPE_TEXT,
         definitions.cICalProperty_POLL_PROPERTIES   : Value.VALUETYPE_TEXT,
+        definitions.cICalProperty_POLL_WINNER       : Value.VALUETYPE_INTEGER,
+        definitions.cICalProperty_RESPONSE          : Value.VALUETYPE_INTEGER,
         definitions.cICalProperty_VOTER             : Value.VALUETYPE_CALADDRESS,
 
         # Apple Extensions

Modified: PyCalendar/trunk/src/pycalendar/icalendar/tests/test_vpoll.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/tests/test_vpoll.py	2015-01-14 15:38:08 UTC (rev 14300)
+++ PyCalendar/trunk/src/pycalendar/icalendar/tests/test_vpoll.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -1,5 +1,5 @@
 ##
-#    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
+#    Copyright (c) 2007-2015 Cyrus Daboo. All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License");
 #    you may not use this file except in compliance with the License.
@@ -32,8 +32,16 @@
 ORGANIZER:mailto:user01 at example.com
 POLL-MODE:BASIC
 POLL-PROPERTIES:DTSTART,DTEND
+BEGIN:VVOTER
 VOTER;CN=User 02:mailto:user02 at example.com
+BEGIN:VOTE
+POLL-ITEM-ID:1
+RESPONSE:100
+END:VOTE
+END:VVOTER
+BEGIN:VVOTER
 VOTER;CN=User 03:mailto:user03 at example.com
+END:VVOTER
 BEGIN:VEVENT
 UID:C3184A66-1ED0-11D9-A5E0-000A958A3252
 DTSTART;VALUE=DATE:20130101
@@ -63,11 +71,21 @@
 UID:A979D282-2CDB-484F-BD63-3972094DFFC0
 DTSTAMP:20020101T000000Z
 ORGANIZER:mailto:user01 at example.com
-POLL-ITEM-ID;PUBLIC-COMMENT=Not ideal;RESPONSE=50:1
-POLL-ITEM-ID;PUBLIC-COMMENT=Perfect;RESPONSE=100:2
 POLL-MODE:BASIC
 POLL-PROPERTIES:DTSTART,DTEND
+BEGIN:VVOTER
 VOTER;CN=User 02:mailto:user02 at example.com
+BEGIN:VOTE
+POLL-ITEM-ID:1
+RESPONSE:50
+COMMENT:Not ideal
+END:VOTE
+BEGIN:VOTE
+POLL-ITEM-ID:2
+RESPONSE:100
+COMMENT:Perfect
+END:VOTE
+END:VVOTER
 END:VPOLL
 END:VCALENDAR
 """,

Added: PyCalendar/trunk/src/pycalendar/icalendar/vote.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/vote.py	                        (rev 0)
+++ PyCalendar/trunk/src/pycalendar/icalendar/vote.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -0,0 +1,51 @@
+##
+#    Copyright (c) 2011-2015 Cyrus Daboo. All rights reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+##
+
+from pycalendar.icalendar import definitions
+from pycalendar.icalendar.component import Component
+from pycalendar.icalendar.validation import ICALENDAR_VALUE_CHECKS
+
+class Vote(Component):
+
+    propertyCardinality_1 = (
+    )
+
+    propertyCardinality_0_1 = (
+        definitions.cICalProperty_POLL_ITEM_ID,
+        definitions.cICalProperty_RESPONSE,
+    )
+
+    propertyValueChecks = ICALENDAR_VALUE_CHECKS
+
+    def __init__(self, parent=None):
+        super(Vote, self).__init__(parent=parent)
+
+
+    def duplicate(self, parent=None):
+        return super(Vote, self).duplicate(parent=parent)
+
+
+    def getType(self):
+        return definitions.cICalComponent_VOTE
+
+
+    def sortedPropertyKeyOrder(self):
+        return (
+            definitions.cICalProperty_POLL_ITEM_ID,
+            definitions.cICalProperty_RESPONSE,
+        )
+
+Component.registerComponent(definitions.cICalComponent_VOTE, Vote)

Modified: PyCalendar/trunk/src/pycalendar/icalendar/vpoll.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/vpoll.py	2015-01-14 15:38:08 UTC (rev 14300)
+++ PyCalendar/trunk/src/pycalendar/icalendar/vpoll.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -1,5 +1,5 @@
 ##
-#    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
+#    Copyright (c) 2007-2015 Cyrus Daboo. All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License");
 #    you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
         definitions.cICalProperty_LAST_MODIFIED,
         definitions.cICalProperty_POLL_MODE,
         definitions.cICalProperty_POLL_PROPERTIES,
+        definitions.cICalProperty_POLL_WINNER,
         definitions.cICalProperty_PRIORITY,
         definitions.cICalProperty_SEQUENCE,
         definitions.cICalProperty_STATUS,
@@ -67,13 +68,18 @@
 
     def sortedComponents(self):
         """
-        Also take POLL-ID into account
+        Also take VVOTER and POLL-ID into account
         """
 
         components = self.mComponents[:]
 
-        # Write out the remainder sorted by name, sortKey
-        return sorted(components, key=lambda x: (x.getType().upper(), x.loadValueString(definitions.cICalProperty_POLL_ITEM_ID),))
+        # VVOTER sorts above components with POLL-ITEM-ID
+        def _sortKey(subcomponent):
+            if subcomponent.getType().upper() == definitions.cICalComponent_VVOTER:
+                return ("0", subcomponent.loadValueString(definitions.cICalProperty_VOTER),)
+            else:
+                return (subcomponent.getType().upper(), subcomponent.loadValueInteger(definitions.cICalProperty_POLL_ITEM_ID),)
+        return sorted(components, key=_sortKey)
 
 
 Component.registerComponent(definitions.cICalComponent_VPOLL, VPoll)

Added: PyCalendar/trunk/src/pycalendar/icalendar/vvoter.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/icalendar/vvoter.py	                        (rev 0)
+++ PyCalendar/trunk/src/pycalendar/icalendar/vvoter.py	2015-01-14 15:39:56 UTC (rev 14301)
@@ -0,0 +1,71 @@
+##
+#    Copyright (c) 2011-2015 Cyrus Daboo. All rights reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+##
+
+from pycalendar.icalendar import definitions
+from pycalendar.icalendar.component import Component
+from pycalendar.icalendar.validation import ICALENDAR_VALUE_CHECKS
+
+class VVoter(Component):
+
+    propertyCardinality_1 = (
+        definitions.cICalProperty_VOTER,
+    )
+
+    propertyCardinality_0_1 = (
+        definitions.cICalProperty_CREATED,
+        definitions.cICalProperty_DESCRIPTION,
+        definitions.cICalProperty_LAST_MODIFIED,
+        definitions.cICalProperty_SUMMARY,
+        definitions.cICalProperty_URL,
+    )
+
+    propertyValueChecks = ICALENDAR_VALUE_CHECKS
+
+    def __init__(self, parent=None):
+        super(VVoter, self).__init__(parent=parent)
+
+
+    def duplicate(self, parent=None):
+        return super(VVoter, self).duplicate(parent=parent)
+
+
+    def getType(self):
+        return definitions.cICalComponent_VVOTER
+
+
+    def addComponent(self, comp):
+        # We can embed the available components only
+        if comp.getType() == definitions.cICalComponent_VOTE:
+            super(VVoter, self).addComponent(comp)
+        else:
+            raise ValueError
+
+
+    def sortedPropertyKeyOrder(self):
+        return (
+            definitions.cICalProperty_VOTER,
+        )
+
+
+    def sortedComponents(self):
+        """
+        Also take POLL-ITEM-ID into account
+        """
+
+        components = self.mComponents[:]
+        return sorted(components, key=lambda x: x.loadValueInteger(definitions.cICalProperty_POLL_ITEM_ID))
+
+Component.registerComponent(definitions.cICalComponent_VVOTER, VVoter)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150114/d106923e/attachment-0001.html>


More information about the calendarserver-changes mailing list