1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/test.ics Thu Oct 23 22:57:11 2008 +0200
1.3 @@ -0,0 +1,18 @@
1.4 +BEGIN:VCALENDAR
1.5 +PRODID:-//vContent//NONSGML vCalendar//EN
1.6 +VERSION:2.0
1.7 +BEGIN:VEVENT
1.8 +DTSTAMP:20081017T233900Z
1.9 +UID:1-test.ics
1.10 +ORGANIZER;ROLE=CHAIR:MAILTO:paul@boddie.org.uk
1.11 +ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:paul@boddie.org.uk
1.12 +DESCRIPTION;ALTREP="http://www.boddie.org.uk/python/vContent.html":Test of vCalendar/iCalendar
1.13 +CATEGORIES:MEETING
1.14 +CLASS:PUBLIC
1.15 +CREATED:20081017T233900Z
1.16 +SUMMARY:Testing
1.17 +DTSTART;TZID=CEST:20081018T150000
1.18 +DTEND;TZID=CEST:20081018T153000
1.19 +LOCATION:Oslo, Norway
1.20 +END:VEVENT
1.21 +END:VCALENDAR
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/test.vcf Thu Oct 23 22:57:11 2008 +0200
2.3 @@ -0,0 +1,13 @@
2.4 +BEGIN:VCARD
2.5 +CATEGORIES:Business
2.6 +CLASS:PUBLIC
2.7 +EMAIL:bjørn@skog.private
2.8 +FN:Bjørn Bear
2.9 +N:Bear;Bjørn;;;
2.10 +ORG:Wildlife
2.11 +REV:2008-10-23T22:38:13Z
2.12 +ROLE:Predator
2.13 +UID:p6uSXHgAu7
2.14 +VERSION:3.0
2.15 +END:VCARD
2.16 +
3.1 --- a/tests/test_calendar.py Sat Oct 18 01:41:15 2008 +0200
3.2 +++ b/tests/test_calendar.py Thu Oct 23 22:57:11 2008 +0200
3.3 @@ -2,7 +2,7 @@
3.4
3.5 import codecs, vCalendar
3.6
3.7 -f = codecs.open("test.ics", encoding="utf-8")
3.8 +f = codecs.open("tests/test.ics", encoding="utf-8")
3.9 doc = vCalendar.parse(f)
3.10
3.11 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/test_calendar_stream.py Thu Oct 23 22:57:11 2008 +0200
4.3 @@ -0,0 +1,8 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +import codecs, vCalendar
4.7 +
4.8 +f = codecs.open("tests/test.ics", encoding="utf-8")
4.9 +doc = vCalendar.iterparse(f)
4.10 +
4.11 +# vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/tests/test_card.py Sat Oct 18 01:41:15 2008 +0200
5.2 +++ b/tests/test_card.py Thu Oct 23 22:57:11 2008 +0200
5.3 @@ -2,7 +2,7 @@
5.4
5.5 import codecs, vContent
5.6
5.7 -f = codecs.open("test.vcf", encoding="utf-8")
5.8 +f = codecs.open("tests/test.vcf", encoding="utf-8")
5.9 doc = vContent.parse(f)
5.10
5.11 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/test_card_stream.py Thu Oct 23 22:57:11 2008 +0200
6.3 @@ -0,0 +1,8 @@
6.4 +#!/usr/bin/env python
6.5 +
6.6 +import codecs, vContent
6.7 +
6.8 +f = codecs.open("tests/test.vcf", encoding="utf-8")
6.9 +doc = vContent.iterparse(f)
6.10 +
6.11 +# vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/vCalendar.py Sat Oct 18 01:41:15 2008 +0200
7.2 +++ b/vCalendar.py Thu Oct 23 22:57:11 2008 +0200
7.3 @@ -27,16 +27,16 @@
7.4 http://rfc.net/rfc2445.html
7.5 """
7.6
7.7 -from vContent import Parser, Reader
7.8 +import vContent
7.9
7.10 try:
7.11 set
7.12 except NameError:
7.13 from sets import Set as set
7.14
7.15 -class vCalendarParser(Parser):
7.16 +class vCalendarStreamParser(vContent.StreamParser):
7.17
7.18 - "A parser specifically for vCalendar/iCalendar."
7.19 + "A stream parser specifically for vCalendar/iCalendar."
7.20
7.21 quoted_parameters = set([
7.22 "ALTREP", "DELEGATED-FROM", "DELEGATED-TO", "DIR", "MEMBER", "SENT-BY"
7.23 @@ -46,6 +46,16 @@
7.24 ])
7.25 quoted_types = set(["URI"])
7.26
7.27 + def next(self):
7.28 +
7.29 + """
7.30 + Return the next content item in the file as a tuple of the form
7.31 + (name, parameters, values).
7.32 + """
7.33 +
7.34 + name, parameters, values = vContent.StreamParser.next(self)
7.35 + return name, self.decode_parameters(parameters), values
7.36 +
7.37 def decode_quoted_value(self, value):
7.38
7.39 "Decode the given 'value', returning a list of decoded values."
7.40 @@ -55,14 +65,14 @@
7.41 else:
7.42 return value
7.43
7.44 - def handleProperty(self, name, parameters, value):
7.45 + def decode_parameters(self, parameters):
7.46
7.47 """
7.48 - Record the property with the given 'name', 'parameters' and 'value' as
7.49 - part of the current component's children.
7.50 + Decode the given 'parameters' according to the vCalendar specification.
7.51 """
7.52
7.53 decoded_parameters = {}
7.54 +
7.55 for param_name, param_value in parameters.items():
7.56 if param_name in self.quoted_parameters:
7.57 param_value = self.decode_quoted_value(param_value)
7.58 @@ -73,7 +83,14 @@
7.59 param_value = param_value.split(separator)
7.60 decoded_parameters[param_name] = param_value
7.61
7.62 - return Parser.handleProperty(self, name, decoded_parameters, value)
7.63 + return decoded_parameters
7.64 +
7.65 +class vCalendarParser(vContent.Parser):
7.66 +
7.67 + "A parser specifically for vCalendar/iCalendar."
7.68 +
7.69 + def parse(self, f, parser_cls=None):
7.70 + return vContent.Parser.parse(self, f, vCalendarStreamParser)
7.71
7.72 # Public functions.
7.73
7.74 @@ -81,9 +98,8 @@
7.75
7.76 """
7.77 Parse the resource data found through the use of the file object 'f', which
7.78 - should provide Unicode data, and put the resource information in the given
7.79 - 'store'. (The codecs module can be used to open files or to wrap streams in
7.80 - order to provide Unicode data.)
7.81 + should provide Unicode data. (The codecs module can be used to open files or
7.82 + to wrap streams in order to provide Unicode data.)
7.83
7.84 The optional 'non_standard_newline' can be set to a true value (unlike the
7.85 default) in order to attempt to process files with CR as the end of line
7.86 @@ -93,8 +109,23 @@
7.87 is returned.
7.88 """
7.89
7.90 - reader = Reader(f, non_standard_newline=non_standard_newline)
7.91 - parser = vCalendarParser()
7.92 - return parser.parse(reader)
7.93 + return vContent.parser(f, non_standard_newline, vCalendarParser)
7.94 +
7.95 +def iterparse(f, non_standard_newline=0):
7.96 +
7.97 + """
7.98 + Parse the resource data found through the use of the file object 'f', which
7.99 + should provide Unicode data. (The codecs module can be used to open files or
7.100 + to wrap streams in order to provide Unicode data.)
7.101 +
7.102 + The optional 'non_standard_newline' can be set to a true value (unlike the
7.103 + default) in order to attempt to process files with CR as the end of line
7.104 + character.
7.105 +
7.106 + An iterator is returned which provides event tuples describing parsing
7.107 + events of the form (name, parameters, value).
7.108 + """
7.109 +
7.110 + return vContent.iterparse(f, non_standard_newline, vCalendarStreamParser)
7.111
7.112 # vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/vContent.py Sat Oct 18 01:41:15 2008 +0200
8.2 +++ b/vContent.py Thu Oct 23 22:57:11 2008 +0200
8.3 @@ -195,6 +195,8 @@
8.4
8.5 return self.parse_content_line()
8.6
8.7 + # Internal methods.
8.8 +
8.9 def parse_content_line(self):
8.10
8.11 """
8.12 @@ -285,11 +287,11 @@
8.13
8.14 self.names = []
8.15
8.16 - def parse(self, f):
8.17 + def parse(self, f, parser_cls=None):
8.18
8.19 "Parse the contents of the file 'f'."
8.20
8.21 - parser = StreamParser(f)
8.22 + parser = (parser_cls or StreamParser)(f)
8.23
8.24 for name, parameters, value in parser:
8.25
8.26 @@ -370,22 +372,21 @@
8.27
8.28 # Public methods.
8.29
8.30 - def parse(self, f):
8.31 + def parse(self, f, parser_cls=None):
8.32
8.33 "Parse the contents of the file 'f'."
8.34
8.35 - ParserBase.parse(self, f)
8.36 + ParserBase.parse(self, f, parser_cls)
8.37 return self.components[0]
8.38
8.39 # Public functions.
8.40
8.41 -def parse(f, non_standard_newline=0):
8.42 +def parse(f, non_standard_newline=0, parser_cls=None):
8.43
8.44 """
8.45 Parse the resource data found through the use of the file object 'f', which
8.46 - should provide Unicode data, and put the resource information in the given
8.47 - 'store'. (The codecs module can be used to open files or to wrap streams in
8.48 - order to provide Unicode data.)
8.49 + should provide Unicode data. (The codecs module can be used to open files or
8.50 + to wrap streams in order to provide Unicode data.)
8.51
8.52 The optional 'non_standard_newline' can be set to a true value (unlike the
8.53 default) in order to attempt to process files with CR as the end of line
8.54 @@ -395,8 +396,27 @@
8.55 is returned.
8.56 """
8.57
8.58 - reader = Reader(f, non_standard_newline=non_standard_newline)
8.59 - parser = Parser()
8.60 + reader = Reader(f, non_standard_newline)
8.61 + parser = (parser_cls or Parser)()
8.62 return parser.parse(reader)
8.63
8.64 +def iterparse(f, non_standard_newline=0, parser_cls=None):
8.65 +
8.66 + """
8.67 + Parse the resource data found through the use of the file object 'f', which
8.68 + should provide Unicode data. (The codecs module can be used to open files or
8.69 + to wrap streams in order to provide Unicode data.)
8.70 +
8.71 + The optional 'non_standard_newline' can be set to a true value (unlike the
8.72 + default) in order to attempt to process files with CR as the end of line
8.73 + character.
8.74 +
8.75 + An iterator is returned which provides event tuples describing parsing
8.76 + events of the form (name, parameters, value).
8.77 + """
8.78 +
8.79 + reader = Reader(f, non_standard_newline)
8.80 + parser = (parser_cls or StreamParser)(reader)
8.81 + return iter(parser)
8.82 +
8.83 # vim: tabstop=4 expandtab shiftwidth=4