test/data/geohash.ics: Pull out geohashing example from Feed doctest
[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     >>> import os
15     >>> root_dir = os.curdir
16     >>> data_file = os.path.join(os.curdir, 'test', 'data', 'geohash.ics')
17     >>> with open(data_file, 'r') as data:
18     ...     f.content = data.read().replace('\n', data.newlines)
19     ...     assert data.newlines == '\r\n', data.newlines
20     >>> print(f)  # doctest: +REPORT_UDIFF
21     BEGIN:VCALENDAR
22     VERSION:2.0
23     PRODID:-//Example Calendar//NONSGML v1.0//EN
24     BEGIN:VEVENT
25     UID:2013-06-30@geohash.invalid
26     DTSTAMP:2013-06-30T00:00:00Z
27     DTSTART;VALUE=DATE:20130630
28     DTEND;VALUE=DATE:20130701
29     SUMMARY:XKCD geohashing\, Boston graticule
30     URL:http://xkcd.com/426/
31     LOCATION:Snow Hill\, Dover\, Massachusetts
32     GEO:42.226663,-71.28676
33     END:VEVENT
34     END:VCALENDAR
35
36     To get the CRLF line endings specified in :RFC:`5545`, use the
37     ``.write`` method.
38
39     >>> import io
40     >>> stream = io.StringIO()
41     >>> f.write(stream=stream)
42     >>> stream.getvalue()  # doctest: +ELLIPSIS
43     'BEGIN:VCALENDAR\r\nVERSION:2.0\r\n...END:VCALENDAR\r\n'
44     """
45     def __init__(self, url, content=None):
46         self.url = url
47         self.content = content
48
49     def __str__(self):
50         if self.content:
51             return self.content.replace('\r\n', '\n').strip()
52         return ''
53
54     def __repr__(self):
55         return '<{} url:{}>'.format(type(self).__name__, self.url)
56
57     def fetch(self):
58         raise NotImplementedError()
59
60     def write(self, stream):
61         stream.write(self.content)