1.1 --- a/vCalendar.py Thu Apr 25 22:11:23 2013 +0200
1.2 +++ b/vCalendar.py Thu Apr 25 22:14:56 2013 +0200
1.3 @@ -32,6 +32,7 @@
1.4 """
1.5
1.6 import vContent
1.7 +import re
1.8
1.9 try:
1.10 set
1.11 @@ -48,6 +49,8 @@
1.12 ])
1.13 QUOTED_TYPES = set(["URI"])
1.14
1.15 +unquoted_comma_regexp = re.compile(r"(?<!\\),")
1.16 +
1.17 # Parser classes.
1.18
1.19 class vCalendarStreamParser(vContent.StreamParser):
1.20 @@ -66,6 +69,15 @@
1.21
1.22 def decode_content(self, value):
1.23
1.24 + """
1.25 + Decode the given 'value' (which may represent a collection of distinct
1.26 + values), replacing quoted separator characters.
1.27 + """
1.28 +
1.29 + return [self.decode_content_value(v) for v in unquoted_comma_regexp.split(value)]
1.30 +
1.31 + def decode_content_value(self, value):
1.32 +
1.33 "Decode the given 'value', replacing quoted separator characters."
1.34
1.35 # Replace quoted characters (see 4.3.11 in RFC 2445).
1.36 @@ -141,6 +153,18 @@
1.37
1.38 def encode_content(self, value):
1.39
1.40 + """
1.41 + Encode the given 'value' (which may be a list or tuple of separate
1.42 + values), quoting characters and separating collections of values.
1.43 + """
1.44 +
1.45 + if not isinstance(value, (list, tuple)):
1.46 + value = [value]
1.47 +
1.48 + return ",".join([self.encode_content_value(v) for v in value])
1.49 +
1.50 + def encode_content_value(self, value):
1.51 +
1.52 "Encode the given 'value', quoting characters."
1.53
1.54 # Replace quoted characters (see 4.3.11 in RFC 2445).