Skip to content
Permalink
Browse files

Initial support for icalendar-patch.

  • Loading branch information
cyrusdaboo committed Dec 10, 2015
1 parent 0859639 commit 47fca56763cfbe23f88b86e498c26dfdfe4509f6
@@ -153,6 +153,14 @@ def removeComponent(self, component):
self.mComponents.remove(component)


def removeFromParent(self):
"""
Remove this L{ComponentBase} from its parent
"""
if self.mParentComponent is not None:
self.mParentComponent.removeComponent(self)


def removeAllComponent(self, compname=None):
if compname:
compname = compname.upper()
@@ -241,31 +241,38 @@ def parse(self, data):

def generate(self, os):
try:
if not self.mForward and (self.mWeeks or self.mDays or self.mHours or self.mMinutes or self.mSeconds):
os.write("-")
os.write("P")
os.write(self.getText())
except:
pass

if self.mWeeks != 0:
os.write("%dW" % (self.mWeeks,))
else:
if self.mDays != 0:
os.write("%dD" % (self.mDays,))

if (self.mHours != 0) or (self.mMinutes != 0) or (self.mSeconds != 0):
os.write("T")
def getText(self):
result = []
if not self.mForward and (self.mWeeks or self.mDays or self.mHours or self.mMinutes or self.mSeconds):
result.append("-")
result.append("P")

if self.mHours != 0:
os.write("%dH" % (self.mHours,))
if self.mWeeks != 0:
result.append("%dW" % (self.mWeeks,))
else:
if self.mDays != 0:
result.append("%dD" % (self.mDays,))

if (self.mMinutes != 0) or ((self.mHours != 0) and (self.mSeconds != 0)):
os.write("%dM" % (self.mMinutes,))
if (self.mHours != 0) or (self.mMinutes != 0) or (self.mSeconds != 0):
result.append("T")

if self.mSeconds != 0:
os.write("%dS" % (self.mSeconds,))
elif self.mDays == 0:
os.write("T0S")
except:
pass
if self.mHours != 0:
result.append("%dH" % (self.mHours,))

if (self.mMinutes != 0) or ((self.mHours != 0) and (self.mSeconds != 0)):
result.append("%dM" % (self.mMinutes,))

if self.mSeconds != 0:
result.append("%dS" % (self.mSeconds,))
elif self.mDays == 0:
result.append("T0S")

return "".join(result)


def writeXML(self, node, namespace):
@@ -45,6 +45,10 @@ def generate(self, os):
pass


def getTextValue(self):
return str(self.mValue)


def writeXML(self, node, namespace):
value = self.getXMLNode(node, namespace)
value.text = str(self.mValue)
@@ -63,7 +63,11 @@ def parse(self, data, variant="icalendar"):

# os - StringIO object
def generate(self, os):
os.write("%s;%s" % (self.mValue[0], self.mValue[1],))
os.write(self.getTextValue())


def getTextValue(self):
return "%s;%s" % (self.mValue[0], self.mValue[1],)


def writeXML(self, node, namespace):
@@ -365,47 +365,8 @@ def deriveComponent(self, recurrenceID):
master = self.masterComponent()
if master is None:
return None

# Create the derived instance
newcomp = master.duplicate()

# Strip out unwanted recurrence properties
for propname in (
definitions.cICalProperty_RRULE,
definitions.cICalProperty_RDATE,
definitions.cICalProperty_EXRULE,
definitions.cICalProperty_EXDATE,
definitions.cICalProperty_RECURRENCE_ID,
):
newcomp.removeProperties(propname)

# New DTSTART is the RECURRENCE-ID we are deriving but adjusted to the
# original DTSTART's localtime
dtstart = newcomp.getStart()
dtend = newcomp.getEnd()
oldduration = dtend - dtstart

newdtstartValue = recurrenceID.duplicate()
if not dtstart.isDateOnly():
if dtstart.local():
newdtstartValue.adjustTimezone(dtstart.getTimezone())
else:
newdtstartValue.setDateOnly(True)

newcomp.removeProperties(definitions.cICalProperty_DTSTART)
newcomp.removeProperties(definitions.cICalProperty_DTEND)
prop = Property(definitions.cICalProperty_DTSTART, newdtstartValue)
newcomp.addProperty(prop)
if not newcomp.useDuration():
prop = Property(definitions.cICalProperty_DTEND, newdtstartValue + oldduration)
newcomp.addProperty(prop)

newcomp.addProperty(Property("RECURRENCE-ID", newdtstartValue))

# After creating/changing a component we need to do this to keep PyCalendar happy
newcomp.finalise()

return newcomp
return master.deriveComponent(recurrenceID)


def masterComponent(self):
@@ -719,5 +719,60 @@ def initFromMaster(self):
self.mEnd = self.mStart + temp


def deriveComponent(self, recurrenceID):
"""
Derive an overridden component for the associated RECURRENCE-ID. This assumes
that the R-ID is valid for the actual recurrence being used. It also assumes
that this component is the master.
@param recurrenceID: the recurrence instance
@type recurrenceID: L{DateTime}
@return: the derived component
@rtype: L{ComponentRecur} or L{None}
"""

# Create the derived instance
newcomp = self.duplicate()

# Strip out unwanted recurrence properties
for propname in (
definitions.cICalProperty_RRULE,
definitions.cICalProperty_RDATE,
definitions.cICalProperty_EXRULE,
definitions.cICalProperty_EXDATE,
definitions.cICalProperty_RECURRENCE_ID,
):
newcomp.removeProperties(propname)

# New DTSTART is the RECURRENCE-ID we are deriving but adjusted to the
# original DTSTART's localtime
dtstart = newcomp.getStart()
dtend = newcomp.getEnd()
oldduration = dtend - dtstart

newdtstartValue = recurrenceID.duplicate()
if not dtstart.isDateOnly():
if dtstart.local():
newdtstartValue.adjustTimezone(dtstart.getTimezone())
else:
newdtstartValue.setDateOnly(True)

newcomp.removeProperties(definitions.cICalProperty_DTSTART)
newcomp.removeProperties(definitions.cICalProperty_DTEND)
prop = Property(definitions.cICalProperty_DTSTART, newdtstartValue)
newcomp.addProperty(prop)
if not newcomp.useDuration():
prop = Property(definitions.cICalProperty_DTEND, newdtstartValue + oldduration)
newcomp.addProperty(prop)

newcomp.addProperty(Property("RECURRENCE-ID", newdtstartValue))

# After creating/changing a component we need to do this to keep PyCalendar happy
newcomp.finalise()

return newcomp


def createExpanded(self, master, recurid):
return ComponentExpanded(master, recurid)

0 comments on commit 47fca56

Please sign in to comment.
You can’t perform that action at this time.