feed: Stub out the Feed class
[pycalendar.git] / pycalendar / feed.py
1 # Copyright
2
3 class Feed (object):
4     r"""An iCalendar feed (:RFC:`5545`)
5
6     >>> f = Feed(url='http://example.com/calendar.ics')
7     >>> f
8     <Feed url:http://example.com/calendar.ics>
9     >>> print(f)
10     <BLANKLINE>
11
12     We can't fetch this dummy url, so load the content by hand.
13
14     >>> f.content = '\r\n'.join([
15     ...         'BEGIN:VCALENDAR',
16     ...         'VERSION:2.0',
17     ...         'PRODID:-//Example Calendar//NONSGML v1.0//EN',
18     ...         'BEGIN:VEVENT',
19     ...         'UID:2013-06-30@geohash.invalid',
20     ...         'DTSTAMP:2013-06-30T00:00:00Z',
21     ...         'DTSTART;VALUE=DATE:20130630',
22     ...         'DTEND;VALUE=DATE:20130701',
23     ...         'SUMMARY:XKCD geohashing, Boston graticule',
24     ...         'URL:http://xkcd.com/426/',
25     ...         'LOCATION:Snow Hill, Dover, Massachusetts',
26     ...         'GEO:42.226663,-71.28676',
27     ...         'END:VEVENT',
28     ...         'END:VCALENDAR',
29     ...         '',
30     ...         ])
31     >>> print(f)
32     BEGIN:VCALENDAR
33     VERSION:2.0
34     PRODID:-//Example Calendar//NONSGML v1.0//EN
35     BEGIN:VEVENT
36     UID:2013-06-30@geohash.invalid
37     DTSTAMP:2013-06-30T00:00:00Z
38     DTSTART;VALUE=DATE:20130630
39     DTEND;VALUE=DATE:20130701
40     SUMMARY:XKCD geohashing, Boston graticule
41     URL:http://xkcd.com/426/
42     LOCATION:Snow Hill, Dover, Massachusetts
43     GEO:42.226663,-71.28676
44     END:VEVENT
45     END:VCALENDAR
46
47     To get the CRLF line endings specified in :RFC:`5545`, use the
48     ``.write`` method.
49
50     >>> import io
51     >>> stream = io.StringIO()
52     >>> f.write(stream=stream)
53     >>> stream.getvalue()  # doctest: +ELLIPSIS
54     'BEGIN:VCALENDAR\r\nVERSION:2.0\r\n...END:VCALENDAR\r\n'
55     """
56     def __init__(self, url, content=None):
57         self.url = url
58         self.content = content
59
60     def __str__(self):
61         if self.content:
62             return self.content.replace('\r\n', '\n').strip()
63         return ''
64
65     def __repr__(self):
66         return '<{} url:{}>'.format(type(self).__name__, self.url)
67
68     def fetch(self):
69         raise NotImplementedError()
70
71     def write(self, stream):
72         stream.write(self.content)