1.1 --- a/EventAggregatorSupport/Resources.py Wed Jan 22 19:19:12 2014 +0100
1.2 +++ b/EventAggregatorSupport/Resources.py Tue Jan 28 01:44:23 2014 +0100
1.3 @@ -2,7 +2,7 @@
1.4 """
1.5 MoinMoin - EventAggregator resource acquisition and access
1.6
1.7 - @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.8 + @copyright: 2008, 2009, 2010, 2011, 2012, 2013, 2014 by Paul Boddie <paul@boddie.org.uk>
1.9 @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 """
1.11
1.12 @@ -13,7 +13,6 @@
1.13 from MoinSupport import *
1.14 from MoinRemoteSupport import getCachedResource, getCachedResourceMetadata
1.15
1.16 -import codecs
1.17 import urllib
1.18
1.19 try:
1.20 @@ -114,8 +113,7 @@
1.21 # NOTE: the content type provided by the URL.
1.22
1.23 if format == "ical" and vCalendar is not None:
1.24 - parser = vCalendar.parse
1.25 - resource_cls = EventCalendar
1.26 + parser = parseEventsInCalendarFromResource
1.27 required_content_type = expected_content_type or "text/calendar"
1.28 else:
1.29 return None
1.30 @@ -141,11 +139,8 @@
1.31
1.32 # Send the data to the parser.
1.33
1.34 - uf = codecs.getreader(encoding or "utf-8")(f)
1.35 - try:
1.36 - return resource_cls(url, parser(uf), metadata)
1.37 - finally:
1.38 - uf.close()
1.39 + return parser(f, encoding, url, metadata)
1.40 +
1.41 finally:
1.42 f.close()
1.43
2.1 --- a/EventAggregatorSupport/Types.py Wed Jan 22 19:19:12 2014 +0100
2.2 +++ b/EventAggregatorSupport/Types.py Tue Jan 28 01:44:23 2014 +0100
2.3 @@ -68,11 +68,31 @@
2.4
2.5 def parseEventsInCalendar(text):
2.6
2.7 - # Make a Unicode-capable StringIO.
2.8 + """
2.9 + Parse events in iCalendar format from the given 'text'.
2.10 + """
2.11 +
2.12 + # Fill the StringIO with encoded plain string data.
2.13 +
2.14 + encoding = "utf-8"
2.15 + calendar = parseEventsInCalendarFromResource(StringIO(text.encode(encoding)), encoding)
2.16 + return calendar.getEvents()
2.17 +
2.18 +def parseEventsInCalendarFromResource(f, encoding=None, url=None, metadata=None):
2.19
2.20 - f = getreader("utf-8")(StringIO(text.encode("utf-8")))
2.21 - calendar = EventCalendar("", vCalendar.parse(f), {})
2.22 - return calendar.getEvents()
2.23 + """
2.24 + Parse events in iCalendar format from the given file-like object 'f', with
2.25 + content having any specified 'encoding' and being described by the given
2.26 + 'url' and 'metadata'.
2.27 + """
2.28 +
2.29 + # Read Unicode from the resource.
2.30 +
2.31 + uf = getreader(encoding or "utf-8")(f)
2.32 + try:
2.33 + return EventCalendar(url or "", vCalendar.parse(uf), metadata or {})
2.34 + finally:
2.35 + uf.close()
2.36
2.37 def parseEvents(text, event_page, fragment=None):
2.38