feed: Stub out the Feed class
authorW. Trevor King <wking@tremily.us>
Sun, 30 Jun 2013 13:25:29 +0000 (09:25 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 30 Jun 2013 16:25:02 +0000 (12:25 -0400)
pycalendar/__init__.py [new file with mode: 0644]
pycalendar/feed.py [new file with mode: 0644]

diff --git a/pycalendar/__init__.py b/pycalendar/__init__.py
new file mode 100644 (file)
index 0000000..b98f164
--- /dev/null
@@ -0,0 +1 @@
+# Copyright
diff --git a/pycalendar/feed.py b/pycalendar/feed.py
new file mode 100644 (file)
index 0000000..1accb08
--- /dev/null
@@ -0,0 +1,72 @@
+# Copyright
+
+class Feed (object):
+    r"""An iCalendar feed (:RFC:`5545`)
+
+    >>> f = Feed(url='http://example.com/calendar.ics')
+    >>> f
+    <Feed url:http://example.com/calendar.ics>
+    >>> print(f)
+    <BLANKLINE>
+
+    We can't fetch this dummy url, so load the content by hand.
+
+    >>> f.content = '\r\n'.join([
+    ...         'BEGIN:VCALENDAR',
+    ...         'VERSION:2.0',
+    ...         'PRODID:-//Example Calendar//NONSGML v1.0//EN',
+    ...         'BEGIN:VEVENT',
+    ...         'UID:2013-06-30@geohash.invalid',
+    ...         'DTSTAMP:2013-06-30T00:00:00Z',
+    ...         'DTSTART;VALUE=DATE:20130630',
+    ...         'DTEND;VALUE=DATE:20130701',
+    ...         'SUMMARY:XKCD geohashing, Boston graticule',
+    ...         'URL:http://xkcd.com/426/',
+    ...         'LOCATION:Snow Hill, Dover, Massachusetts',
+    ...         'GEO:42.226663,-71.28676',
+    ...         'END:VEVENT',
+    ...         'END:VCALENDAR',
+    ...         '',
+    ...         ])
+    >>> print(f)
+    BEGIN:VCALENDAR
+    VERSION:2.0
+    PRODID:-//Example Calendar//NONSGML v1.0//EN
+    BEGIN:VEVENT
+    UID:2013-06-30@geohash.invalid
+    DTSTAMP:2013-06-30T00:00:00Z
+    DTSTART;VALUE=DATE:20130630
+    DTEND;VALUE=DATE:20130701
+    SUMMARY:XKCD geohashing, Boston graticule
+    URL:http://xkcd.com/426/
+    LOCATION:Snow Hill, Dover, Massachusetts
+    GEO:42.226663,-71.28676
+    END:VEVENT
+    END:VCALENDAR
+
+    To get the CRLF line endings specified in :RFC:`5545`, use the
+    ``.write`` method.
+
+    >>> import io
+    >>> stream = io.StringIO()
+    >>> f.write(stream=stream)
+    >>> stream.getvalue()  # doctest: +ELLIPSIS
+    'BEGIN:VCALENDAR\r\nVERSION:2.0\r\n...END:VCALENDAR\r\n'
+    """
+    def __init__(self, url, content=None):
+        self.url = url
+        self.content = content
+
+    def __str__(self):
+        if self.content:
+            return self.content.replace('\r\n', '\n').strip()
+        return ''
+
+    def __repr__(self):
+        return '<{} url:{}>'.format(type(self).__name__, self.url)
+
+    def fetch(self):
+        raise NotImplementedError()
+
+    def write(self, stream):
+        stream.write(self.content)