def expand(self, start, range, items, float_offset=0): # Need to return whether the limit was applied or not limited = False # Now create list of items to include include = [] # Always include the initial DTSTART if within the range if range.isDateWithinPeriod(start): include.append(start) else: limited = True # RRULES for iter in self.mRrules: if iter.expand(start, range, include, float_offset=float_offset): limited = True # RDATES for iter in self.mRdates: if range.isDateWithinPeriod(iter): include.append(iter) else: limited = True for iter in self.mRperiods: if range.isPeriodOverlap(iter): include.append(iter.getStart()) else: limited = True # Make sure the list is unique include = [x for x in set(include)] include.sort(key=lambda x: x.getPosixTime()) # Now create list of items to exclude exclude = [] # EXRULES for iter in self.mExrules: iter.expand(start, range, exclude, float_offset=float_offset) # EXDATES for iter in self.mExdates: if range.isDateWithinPeriod(iter): exclude.append(iter) for iter in self.mExperiods: if range.isPeriodOverlap(iter): exclude.append(iter.getStart()) # Make sure the list is unique exclude = [x for x in set(exclude)] exclude.sort(key=lambda x: x.getPosixTime()) # Add difference between to the two sets (include - exclude) to the # results items.extend(set_difference(include, exclude)) return limited
def expand(self, start, range, items, float_offset=0, maxInstances=None): # Need to return whether the limit was applied or not limited = False # Now create list of items to include include = [] # Always include the initial DTSTART if within the range if range.isDateWithinPeriod(start): include.append(start) else: limited = True # RRULES for iter in self.mRrules: if iter.expand(start, range, include, float_offset=float_offset, maxInstances=maxInstances): limited = True # RDATES for iter in self.mRdates: if range.isDateWithinPeriod(iter): include.append(iter) if maxInstances and len(include) > maxInstances: raise TooManyInstancesError("Too many instances") else: limited = True for iter in self.mRperiods: if range.isPeriodOverlap(iter): include.append(iter.getStart()) if maxInstances and len(include) > maxInstances: raise TooManyInstancesError("Too many instances") else: limited = True # Make sure the list is unique include = [x for x in set(include)] include.sort(key=lambda x: x.getPosixTime()) # Now create list of items to exclude exclude = [] # EXRULES for iter in self.mExrules: iter.expand(start, range, exclude, float_offset=float_offset) # EXDATES for iter in self.mExdates: if range.isDateWithinPeriod(iter): exclude.append(iter) for iter in self.mExperiods: if range.isPeriodOverlap(iter): exclude.append(iter.getStart()) # Make sure the list is unique exclude = [x for x in set(exclude)] exclude.sort(key=lambda x: x.getPosixTime()) # Add difference between to the two sets (include - exclude) to the # results items.extend(set_difference(include, exclude)) return limited
def expandPeriod(self, period, results): # Check for recurrence and True master if ((self.mRecurrences is not None) and self.mRecurrences.hasRecurrence() and not self.isRecurrenceInstance()): # Expand recurrences within the range items = [] self.mRecurrences.expand(self.mStart, period, items) # Look for overridden recurrence items cal = self.mParentComponent if cal is not None: # Remove recurrence instances from the list of items recurs = [] cal.getRecurrenceInstancesIds( definitions.cICalComponent_VEVENT, self.getUID(), recurs) recurs.sort() if len(recurs) != 0: temp = [] temp = set_difference(items, recurs) items = temp # Now get actual instances instances = [] cal.getRecurrenceInstancesItems( definitions.cICalComponent_VEVENT, self.getUID(), instances) # Get list of each ones with RANGE prior = [] future = [] for iter in instances: if iter.isAdjustPrior(): prior.append(iter) if iter.isAdjustFuture(): future.append(iter) # Check for special behaviour if len(prior) + len(future) == 0: # Add each expanded item for iter in items: results.append(self.createExpanded(self, iter)) else: # Sort each list first prior.sort(self.sort_by_dtstart) future.sort(self.sort_by_dtstart) # Add each expanded item for iter1 in items: # Now step through each using the slave item # instead of the master as appropriate slave = None # Find most appropriate THISANDPRIOR item for i in range(len(prior) - 1, 0, -1): riter2 = prior[i] if riter2.getStart() > iter1: slave = riter2 break # Find most appropriate THISANDFUTURE item for i in range(len(future) - 1, 0, -1): riter2 = future.elementAt(i) if riter2.getStart() < iter1: slave = riter2 break if slave is None: slave = self results.append(self.createExpanded(slave, iter1)) else: # Add each expanded item for iter in items: results.append(self.createExpanded(self, iter)) elif self.withinPeriod(period): if self.isRecurrenceInstance(): rid = self.mRecurrenceID else: rid = None results.append(ComponentExpanded(self, rid))
def expandPeriod(self, period, results): # Check for recurrence and True master if ((self.mRecurrences is not None) and self.mRecurrences.hasRecurrence() and not self.isRecurrenceInstance()): # Expand recurrences within the range items = [] self.mRecurrences.expand(self.mStart, period, items) # Look for overridden recurrence items cal = self.mParentComponent if cal is not None: # Remove recurrence instances from the list of items recurs = [] cal.getRecurrenceInstancesIds(definitions.cICalComponent_VEVENT, self.getUID(), recurs) recurs.sort() if len(recurs) != 0: temp = [] temp = set_difference(items, recurs) items = temp # Now get actual instances instances = [] cal.getRecurrenceInstancesItems(definitions.cICalComponent_VEVENT, self.getUID(), instances) # Get list of each ones with RANGE prior = [] future = [] for iter in instances: if iter.isAdjustPrior(): prior.append(iter) if iter.isAdjustFuture(): future.append(iter) # Check for special behaviour if len(prior) + len(future) == 0: # Add each expanded item for iter in items: results.append(self.createExpanded(self, iter)) else: # Sort each list first prior.sort(self.sort_by_dtstart) future.sort(self.sort_by_dtstart) # Add each expanded item for iter1 in items: # Now step through each using the slave item # instead of the master as appropriate slave = None # Find most appropriate THISANDPRIOR item for i in range(len(prior) - 1, 0, -1): riter2 = prior[i] if riter2.getStart() > iter1: slave = riter2 break # Find most appropriate THISANDFUTURE item for i in range(len(future) - 1, 0, -1): riter2 = future.elementAt(i) if riter2.getStart() < iter1: slave = riter2 break if slave is None: slave = self results.append(self.createExpanded(slave, iter1)) else: # Add each expanded item for iter in items: results.append(self.createExpanded(self, iter)) elif self.withinPeriod(period): if self.isRecurrenceInstance(): rid = self.mRecurrenceID else: rid = None results.append(ComponentExpanded(self, rid))