[CalendarServer-changes] [11594] PyCalendar/branches/json-2

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 10 08:34:43 PDT 2013


Revision: 11594
          http://trac.calendarserver.org//changeset/11594
Author:   cdaboo at apple.com
Date:     2013-08-10 08:34:43 -0700 (Sat, 10 Aug 2013)
Log Message:
-----------
Merge from trunk.

Modified Paths:
--------------
    PyCalendar/branches/json-2/src/pycalendar/calendar.py
    PyCalendar/branches/json-2/src/pycalendar/recurrence.py
    PyCalendar/branches/json-2/src/pycalendar/tests/test_recurrence.py

Property Changed:
----------------
    PyCalendar/branches/json-2/


Property changes on: PyCalendar/branches/json-2
___________________________________________________________________
Modified: svn:mergeinfo
   - /PyCalendar/branches/duplicate-items:10464-10465
/PyCalendar/branches/revised-api-126:10457-10463
/PyCalendar/branches/server:10466-10553
   + /PyCalendar/branches/duplicate-items:10464-10465
/PyCalendar/branches/revised-api-126:10457-10463
/PyCalendar/branches/server:10466-10553
/PyCalendar/trunk:11324-11593

Modified: PyCalendar/branches/json-2/src/pycalendar/calendar.py
===================================================================
--- PyCalendar/branches/json-2/src/pycalendar/calendar.py	2013-08-10 15:33:03 UTC (rev 11593)
+++ PyCalendar/branches/json-2/src/pycalendar/calendar.py	2013-08-10 15:34:43 UTC (rev 11594)
@@ -147,6 +147,33 @@
         return result
 
 
+    def changeUID(self, oldUID, newUID):
+        """
+        Change the UID of all components with a matching UID to a new value. We need to
+        do this at the calendar level because this object maintains mappings based on UID
+        which need to be updated whenever the UID changes.
+
+        @param oldUID: the old value to match
+        @type oldUID: C{str}
+        @param newUID: the new value to match
+        @type newUID: C{str}
+        """
+
+        # Each component
+        for component in self.mComponents:
+            if component.getUID() == oldUID:
+                component.setUID(newUID)
+
+        # Maps
+        if oldUID in self.mOverriddenComponentsByUID:
+            self.mOverriddenComponentsByUID[newUID] = self.mOverriddenComponentsByUID[oldUID]
+            del self.mOverriddenComponentsByUID[oldUID]
+        for ctype in self.mMasterComponentsByTypeAndUID:
+            if oldUID in self.mMasterComponentsByTypeAndUID[ctype]:
+                self.mMasterComponentsByTypeAndUID[ctype][newUID] = self.mMasterComponentsByTypeAndUID[ctype][oldUID]
+                del self.mMasterComponentsByTypeAndUID[ctype][oldUID]
+
+
     def finalise(self):
         # Get calendar name if present
 

Modified: PyCalendar/branches/json-2/src/pycalendar/recurrence.py
===================================================================
--- PyCalendar/branches/json-2/src/pycalendar/recurrence.py	2013-08-10 15:33:03 UTC (rev 11593)
+++ PyCalendar/branches/json-2/src/pycalendar/recurrence.py	2013-08-10 15:34:43 UTC (rev 11594)
@@ -266,12 +266,18 @@
         return True
 
 
+    def _setAndclearIfChanged(self, attr, value):
+        if getattr(self, attr) != value:
+            self.clear()
+            setattr(self, attr, value)
+
+
     def getFreq(self):
         return self.mFreq
 
 
     def setFreq(self, freq):
-        self.mFreq = freq
+        self._setAndclearIfChanged("mFreq", freq)
 
 
     def getUseUntil(self):
@@ -279,7 +285,7 @@
 
 
     def setUseUntil(self, use_until):
-        self.mUseUntil = use_until
+        self._setAndclearIfChanged("mUseUntil", use_until)
 
 
     def getUntil(self):
@@ -287,7 +293,7 @@
 
 
     def setUntil(self, until):
-        self.mUntil = until
+        self._setAndclearIfChanged("mUntil", until)
 
 
     def getUseCount(self):
@@ -295,7 +301,7 @@
 
 
     def setUseCount(self, use_count):
-        self.mUseCount = use_count
+        self._setAndclearIfChanged("mUseCount", use_count)
 
 
     def getCount(self):
@@ -303,7 +309,7 @@
 
 
     def setCount(self, count):
-        self.mCount = count
+        self._setAndclearIfChanged("mCount", count)
 
 
     def getInterval(self):
@@ -311,7 +317,7 @@
 
 
     def setInterval(self, interval):
-        self.mInterval = interval
+        self._setAndclearIfChanged("mInterval", interval)
 
 
     def getByMonth(self):
@@ -319,7 +325,7 @@
 
 
     def setByMonth(self, by):
-        self.mByMonth = by[:]
+        self._setAndclearIfChanged("mByMonth", by[:])
 
 
     def getByMonthDay(self):
@@ -327,7 +333,7 @@
 
 
     def setByMonthDay(self, by):
-        self.mByMonthDay = by[:]
+        self._setAndclearIfChanged("mByMonthDay", by[:])
 
 
     def getByYearDay(self):
@@ -335,7 +341,7 @@
 
 
     def setByYearDay(self, by):
-        self.mByYearDay = by[:]
+        self._setAndclearIfChanged("mByYearDay", by[:])
 
 
     def getByDay(self):
@@ -343,7 +349,7 @@
 
 
     def setByDay(self, by):
-        self.mByDay = by[:]
+        self._setAndclearIfChanged("mByDay", by[:])
 
 
     def getBySetPos(self):
@@ -351,7 +357,7 @@
 
 
     def setBySetPos(self, by):
-        self.mBySetPos = by
+        self._setAndclearIfChanged("mBySetPos", by[:])
 
 
     def parse(self, data):
@@ -734,7 +740,7 @@
     def isAdvancedRule(self):
         # One that has BYMONTH,
         # BYMONTHDAY (with no negative value),
-        # BYDAY (with multiple unumbered, or numbered with all the same number
+        # BYDAY (with multiple unnumbered, or numbered with all the same number
         # (1..4, -2, -1)
         # BYSETPOS with +1, or -1 only
         # no others
@@ -979,7 +985,7 @@
 
     # Exclude dates on or after the chosen one
     def excludeFutureRecurrence(self, exclude):
-        # Expand the rule upto the exclude date
+        # Expand the rule up to the exclude date
         items = []
         period = PyCalendarPeriod()
         period.init(self.mCacheStart, exclude)

Modified: PyCalendar/branches/json-2/src/pycalendar/tests/test_recurrence.py
===================================================================
--- PyCalendar/branches/json-2/src/pycalendar/tests/test_recurrence.py	2013-08-10 15:33:03 UTC (rev 11593)
+++ PyCalendar/branches/json-2/src/pycalendar/tests/test_recurrence.py	2013-08-10 15:34:43 UTC (rev 11594)
@@ -138,3 +138,24 @@
             ],
         )
         print items
+
+
+    def testClearOnChange(self):
+
+        recur = PyCalendarRecurrence()
+        recur.parse("FREQ=DAILY")
+
+        start = PyCalendarDateTime(2013, 1, 1, 0, 0, 0)
+        end = PyCalendarDateTime(2017, 1, 1, 0, 0, 0)
+        range = PyCalendarPeriod(start, end)
+        items = []
+        recur.expand(start, range, items)
+        self.assertTrue(recur.mCached)
+        self.assertTrue(len(items) > 100)
+
+        recur.setUseCount(True)
+        recur.setCount(10)
+        self.assertFalse(recur.mCached)
+        items = []
+        recur.expand(start, range, items)
+        self.assertEqual(len(items), 10)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130810/074b658c/attachment-0001.html>


More information about the calendarserver-changes mailing list