1.1 --- a/EventAggregatorSupport/Types.py Sun Apr 06 23:35:52 2014 +0200
1.2 +++ b/EventAggregatorSupport/Types.py Mon Apr 07 23:16:49 2014 +0200
1.3 @@ -352,6 +352,12 @@
1.4
1.5 return self.metadata or {}
1.6
1.7 + def getMethod(self):
1.8 +
1.9 + "Return the iTIP-related method associated with this resource."
1.10 +
1.11 + return None
1.12 +
1.13 def getEvents(self):
1.14
1.15 "Return a list of events from this resource."
1.16 @@ -412,9 +418,15 @@
1.17
1.18 "An iCalendar resource."
1.19
1.20 + calendar_properties = ("METHOD",)
1.21 +
1.22 def __init__(self, url, calendar, metadata):
1.23 EventCalendarResource.__init__(self, url, metadata)
1.24 self.calendar = calendar
1.25 + self.properties = {}
1.26 +
1.27 + def getMethod(self):
1.28 + return self.properties.get("METHOD")
1.29
1.30 def getEvents(self):
1.31
1.32 @@ -482,6 +494,11 @@
1.33
1.34 self.events.append(CalendarEvent(self, details))
1.35
1.36 + # Obtain calendar-level information.
1.37 +
1.38 + elif objtype in self.calendar_properties:
1.39 + self.properties[objtype] = obj
1.40 +
1.41 return self.events
1.42
1.43 class EventXMLCalendar(EventCalendarResource):
1.44 @@ -492,7 +509,11 @@
1.45
1.46 # See: http://tools.ietf.org/html/draft-daboo-et-al-icalendar-in-xml-11#section-3.4
1.47
1.48 - properties = [
1.49 + calendar_properties = [
1.50 + ("method", "xcal:properties/xcal:method", "getText"),
1.51 + ]
1.52 +
1.53 + event_properties = [
1.54 ("summary", "xcal:properties/xcal:summary", "getText"),
1.55 ("location", "xcal:properties/xcal:location", "getText"),
1.56 ("start", "xcal:properties/xcal:dtstart", "getDateTime"),
1.57 @@ -509,6 +530,10 @@
1.58 def __init__(self, url, doc, metadata):
1.59 EventCalendarResource.__init__(self, url, metadata)
1.60 self.doc = doc
1.61 + self.properties = self.getProperties(self.calendar_properties, doc)
1.62 +
1.63 + def getMethod(self):
1.64 + return self.properties.get("method")
1.65
1.66 def getEvents(self):
1.67
1.68 @@ -518,28 +543,34 @@
1.69 self.events = []
1.70
1.71 for event in self.doc.xpath("//xcal:vevent", namespaces=self.XCAL):
1.72 - details = {}
1.73 -
1.74 - for property, path, converter in self.properties:
1.75 - values = event.xpath(path, namespaces=self.XCAL)
1.76 -
1.77 - try:
1.78 - value = getattr(self, converter)(property, values)
1.79 - details[property] = value
1.80 - except (IndexError, ValueError):
1.81 - pass
1.82 -
1.83 + details = self.getProperties(self.event_properties, event)
1.84 self.events.append(CalendarEvent(self, details))
1.85
1.86 return self.events
1.87
1.88 + # Retrieval methods.
1.89 +
1.90 + def getProperties(self, definitions, root):
1.91 + details = {}
1.92 +
1.93 + for property, path, converter in definitions:
1.94 + values = root.xpath(path, namespaces=self.XCAL)
1.95 +
1.96 + try:
1.97 + value = getattr(self, converter)(property, values)
1.98 + details[property] = value
1.99 + except (IndexError, ValueError), exc:
1.100 + pass
1.101 +
1.102 + return details
1.103 +
1.104 # Parsing methods.
1.105
1.106 def _getValue(self, values, type):
1.107 - for element in values[0].xpath("xcal:%s" % type, namespaces=self.XCAL):
1.108 - return element.textContent
1.109 - else:
1.110 - return None
1.111 + if values:
1.112 + for element in values[0].xpath("xcal:%s" % type, namespaces=self.XCAL):
1.113 + return element.textContent
1.114 + return None
1.115
1.116 def getText(self, property, values):
1.117 return self._getValue(values, "text")