# Sort the list by period self.mBusyTime.sort(cmp=lambda x, y: x.getPeriod().getStart().compareDateTime(y.getPeriod().getStart())) # Determine range start = DateTime() end = DateTime() if self.mHasStart: start = self.mStart else: start = min_start if self.mHasEnd: end = self.mEnd else: end = max_end self.mSpanPeriod = Period(start, end) self.mCachedBusyTime = True def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) Component.registerComponent(definitions.cICalComponent_VFREEBUSY, VFreeBusy)
elif status == definitions.eStatus_VToDo_Cancelled: value = definitions.cICalProperty_STATUS_CANCELLED prop = Property(definitions.cICalProperty_STATUS, value) self.addProperty(prop) def editCompleted(self, completed): # Remove existing COMPLETED item self.removeProperties(definitions.cICalProperty_COMPLETED) self.mHasCompleted = False # Always UTC self.mCompleted = completed.duplicate() self.mCompleted.adjustToUTC() self.mHasCompleted = True prop = Property(definitions.cICalProperty_STATUS_COMPLETED, self.mCompleted) self.addProperty(prop) def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_RECURRENCE_ID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DUE, definitions.cICalProperty_COMPLETED, ) Component.registerComponent(definitions.cICalComponent_VTODO, VToDo)
utc_results = [] for items in set(results): items = list(items) utcdt = items[0].duplicate() utcdt.offsetSeconds(-items[1]) utcdt.setTimezoneUTC(True) items.insert(1, utcdt) utc_results.append(tuple(items)) utc_results.sort(key=lambda x: x[0].getPosixTime()) return utc_results def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_TZID, definitions.cICalProperty_LAST_MODIFIED, definitions.cICalProperty_TZURL, ) @staticmethod def sortByUTCOffsetComparator(tz1, tz2): sort1 = tz1.getUTCOffsetSortKey() sort2 = tz2.getUTCOffsetSortKey() if sort1 == sort2: return tz1.getID().compareToIgnoreCase(tz2.getID()) else: return (1, -1)[sort1 < sort2] Component.registerComponent(definitions.cICalComponent_VTIMEZONE, VTimezone)
def duplicate(self, parent=None): return super(UnknownComponent, self).duplicate(parent=parent, comptype=self.mType) def getType(self): return self.mType def getBeginDelimiter(self): return "BEGIN:" + self.mType def getEndDelimiter(self): return "END:" + self.mType def getMimeComponentName(self): return "unknown" def getMapKey(self): return self.mMapKey def getSortKey(self): """ We do not want unknown components sorted. """ return "" def sortedPropertyKeyOrder(self): return (definitions.cICalProperty_UID,) Component.registerComponent(definitions.cICalComponent_UNKNOWN, UnknownComponent)
# Check for completion if trigger == self.mLastTrigger or ( nowutc - trigger).getTotalSeconds() > 24 * 60 * 60: if self.mDoneCount == self.mRepeats: self.mAlarmStatus = definitions.eAlarm_Status_Completed return else: trigger = trigger + self.mRepeatInterval self.mDoneCount += 1 self.mNextTrigger = trigger def getFirstTrigger(self, dt): # If absolute trigger, use that if self.isTriggerAbsolute(): # Get the trigger on dt.copy(self.getTriggerOn()) else: # Get the parent embedder class (must be CICalendarComponentRecur type) owner = self.getEmbedder() if owner is not None: # Determine time at which alarm will trigger trigger = (owner.getStart(), owner.getEnd())[not self.isTriggerOnStart()] # Offset by duration dt.copy(trigger + self.getTriggerDuration()) Component.registerComponent(definitions.cICalComponent_VALARM, VAlarm)
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)
return super(UnknownComponent, self).duplicate(parent=parent, comptype=self.mType) def getType(self): return self.mType def getBeginDelimiter(self): return "BEGIN:" + self.mType def getEndDelimiter(self): return "END:" + self.mType def getMimeComponentName(self): return "unknown" def getMapKey(self): return self.mMapKey def getSortKey(self): """ We do not want unknown components sorted. """ return "" def sortedPropertyKeyOrder(self): return (definitions.cICalProperty_UID, ) Component.registerComponent(definitions.cICalComponent_UNKNOWN, UnknownComponent)
super(VAvailability, self).addComponent(comp) else: raise ValueError( "Only 'AVAILABLE' components allowed in 'VAVAILABILITY'") def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) def getTimezones(self, tzids): """ In addition to looking in the VAVAILABILITY component, we must also return any TZIDs used in AVAILABLE child components. @param tzids: result to report back @type tzids: L{set} """ super(VAvailability, self).getTimezones(tzids) for available in self.getComponents( definitions.cICalComponent_AVAILABLE): available.getTimezones(tzids) Component.registerComponent(definitions.cICalComponent_VAVAILABILITY, VAvailability)
propertyValueChecks = ICALENDAR_VALUE_CHECKS def __init__(self, parent=None): super(VJournal, self).__init__(parent=parent) def duplicate(self, parent=None): return super(VJournal, self).duplicate(parent=parent) def getType(self): return definitions.cICalComponent_VJOURNAL def getMimeComponentName(self): return itipdefinitions.cICalMIMEComponent_VJOURNAL def finalise(self): super(VJournal, self).finalise() def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_RECURRENCE_ID, definitions.cICalProperty_DTSTART, ) Component.registerComponent(definitions.cICalComponent_VJOURNAL, VJournal)
trigger = next_trigger # Check for completion if trigger == self.mLastTrigger or (nowutc - trigger).getTotalSeconds() > 24 * 60 * 60: if self.mDoneCount == self.mRepeats: self.mAlarmStatus = definitions.eAlarm_Status_Completed return else: trigger = trigger + self.mRepeatInterval self.mDoneCount += 1 self.mNextTrigger = trigger def getFirstTrigger(self, dt): # If absolute trigger, use that if self.isTriggerAbsolute(): # Get the trigger on dt.copy(self.getTriggerOn()) else: # Get the parent embedder class (must be CICalendarComponentRecur type) owner = self.getEmbedder() if owner is not None: # Determine time at which alarm will trigger trigger = (owner.getStart(), owner.getEnd())[not self.isTriggerOnStart()] # Offset by duration dt.copy(trigger + self.getTriggerDuration()) Component.registerComponent(definitions.cICalComponent_VALARM, VAlarm)
definitions.cICalProperty_DTEND, ) def sortedComponents(self): """ Also take VVOTER and POLL-ID into account """ components = self.mComponents[:] # 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)
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)
# 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.vtimezoneelement import VTimezoneElement class Daylight(VTimezoneElement): def __init__(self, parent=None): super(Daylight, self).__init__(parent=parent) def duplicate(self, parent=None): return super(Daylight, self).duplicate(parent=parent) def getType(self): return definitions.cICalComponent_DAYLIGHT Component.registerComponent(definitions.cICalComponent_DAYLIGHT, Daylight)
# 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.vtimezoneelement import VTimezoneElement class Standard(VTimezoneElement): def __init__(self, parent=None): super(Standard, self).__init__(parent=parent) def duplicate(self, parent=None): return super(Standard, self).duplicate(parent=parent) def getType(self): return definitions.cICalComponent_STANDARD Component.registerComponent(definitions.cICalComponent_STANDARD, Standard)
def getMimeComponentName(self): return itipdefinitions.cICalMIMEComponent_VPOLL def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) def sortedComponents(self): """ Also take VVOTER and POLL-ID into account """ components = self.mComponents[:] # 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)
""" fixed, unfixed = super(Available, self).validate(doFix) # Extra constraint: only one of DTEND or DURATION if self.hasProperty(definitions.cICalProperty_DTEND) and self.hasProperty(definitions.cICalProperty_DURATION): # Fix by removing the DTEND logProblem = "[%s] Properties must not both be present: %s, %s" % ( self.getType(), definitions.cICalProperty_DTEND, definitions.cICalProperty_DURATION, ) if doFix: self.removeProperties(definitions.cICalProperty_DTEND) fixed.append(logProblem) else: unfixed.append(logProblem) return fixed, unfixed def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_RECURRENCE_ID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) Component.registerComponent(definitions.cICalComponent_AVAILABLE, Available)
# Sort the list by period self.mBusyTime.sort(cmp=lambda x, y: x.getPeriod().getStart(). compareDateTime(y.getPeriod().getStart())) # Determine range start = DateTime() end = DateTime() if self.mHasStart: start = self.mStart else: start = min_start if self.mHasEnd: end = self.mEnd else: end = max_end self.mSpanPeriod = Period(start, end) self.mCachedBusyTime = True def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) Component.registerComponent(definitions.cICalComponent_VFREEBUSY, VFreeBusy)
self.removeProperties(definitions.cICalProperty_STATUS) # Now create properties value = None if status == definitions.eStatus_VEvent_None: pass elif status == definitions.eStatus_VEvent_Tentative: value = definitions.cICalProperty_STATUS_TENTATIVE elif status == definitions.eStatus_VEvent_Confirmed: value = definitions.cICalProperty_STATUS_CONFIRMED elif status == definitions.eStatus_VEvent_Cancelled: value = definitions.cICalProperty_STATUS_CANCELLED else: pass if value is not None: prop = Property(definitions.cICalProperty_STATUS, value) self.addProperty(prop) def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_RECURRENCE_ID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) Component.registerComponent(definitions.cICalComponent_VEVENT, VEvent)
# 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.vtimezoneelement import VTimezoneElement class Standard(VTimezoneElement): def __init__(self, parent=None): super(Standard, self).__init__(parent=parent) def duplicate(self, parent=None): return super(Standard, self).duplicate(parent=parent) def getType(self): return definitions.cICalComponent_STANDARD Component.registerComponent(definitions.cICalComponent_STANDARD, Standard)
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("Only 'VOTE' components allowed in 'VVOTER'") 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)
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)
definitions.cICalProperty_URL, definitions.cICalProperty_RRULE, ) propertyValueChecks = ICALENDAR_VALUE_CHECKS def __init__(self, parent=None): super(VJournal, self).__init__(parent=parent) def duplicate(self, parent=None): return super(VJournal, self).duplicate(parent=parent) def getType(self): return definitions.cICalComponent_VJOURNAL def getMimeComponentName(self): return itipdefinitions.cICalMIMEComponent_VJOURNAL def finalise(self): super(VJournal, self).finalise() def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_RECURRENCE_ID, definitions.cICalProperty_DTSTART, ) Component.registerComponent(definitions.cICalComponent_VJOURNAL, VJournal)
# We can embed the available components only if comp.getType() == definitions.cICalComponent_AVAILABLE: super(VAvailability, self).addComponent(comp) else: raise ValueError def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) def getTimezones(self, tzids): """ In addition to looking in the VAVAILABILITY component, we must also return any TZIDs used in AVAILABLE child components. @param tzids: result to report back @type tzids: L{set} """ super(VAvailability, self).getTimezones(tzids) for available in self.getComponents(definitions.cICalComponent_AVAILABLE): available.getTimezones(tzids) Component.registerComponent(definitions.cICalComponent_VAVAILABILITY, VAvailability)
# Extra constraint: only one of DTEND or DURATION if self.hasProperty( definitions.cICalProperty_DTEND) and self.hasProperty( definitions.cICalProperty_DURATION): # Fix by removing the DTEND logProblem = "[%s] Properties must not both be present: %s, %s" % ( self.getType(), definitions.cICalProperty_DTEND, definitions.cICalProperty_DURATION, ) if doFix: self.removeProperties(definitions.cICalProperty_DTEND) fixed.append(logProblem) else: unfixed.append(logProblem) return fixed, unfixed def sortedPropertyKeyOrder(self): return ( definitions.cICalProperty_UID, definitions.cICalProperty_RECURRENCE_ID, definitions.cICalProperty_DTSTART, definitions.cICalProperty_DURATION, definitions.cICalProperty_DTEND, ) Component.registerComponent(definitions.cICalComponent_AVAILABLE, Available)
# 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.vtimezoneelement import VTimezoneElement class Daylight(VTimezoneElement): def __init__(self, parent=None): super(Daylight, self).__init__(parent=parent) def duplicate(self, parent=None): return super(Daylight, self).duplicate(parent=parent) def getType(self): return definitions.cICalComponent_DAYLIGHT Component.registerComponent(definitions.cICalComponent_DAYLIGHT, Daylight)