# HG changeset patch # User Paul Boddie # Date 1511543517 -3600 # Node ID c675f7bdd52d178533bb4d6bcb5e6b9afa616fd9 # Parent 7023d88d726051bae98f61b9d72199f383553a7f Extended the value decoding and encoding mechanisms to avoid splitting RRULE values using commas and quoting commas in encoded RRULE values. diff -r 7023d88d7260 -r c675f7bdd52d vCalendar.py --- a/vCalendar.py Tue Jun 06 00:02:05 2017 +0200 +++ b/vCalendar.py Fri Nov 24 18:11:57 2017 +0100 @@ -3,7 +3,8 @@ """ Parsing of vCalendar and iCalendar files. -Copyright (C) 2008, 2009, 2011, 2013, 2014 Paul Boddie +Copyright (C) 2008, 2009, 2011, 2013, 2014, 2015, + 2016, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -53,9 +54,13 @@ MULTIVALUED_PARAMETERS = set([ "DELEGATED-FROM", "DELEGATED-TO", "MEMBER" ]) +NON_MULTIVALUED_PROPERTIES = set([ + "RRULE" + ]) QUOTED_TYPES = set(["URI"]) unquoted_separator_regexp = re.compile(r"(? + 2014, 2015, 2017 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -280,9 +280,12 @@ return self.parse_content_line() - def decode_content(self, value): + def decode_content(self, name, value): - "Decode the given 'value', replacing quoted characters." + """ + Decode for property 'name' the given 'value', replacing quoted + characters. + """ return value.replace("\r", "").replace("\\N", "\n").replace("\\n", "\n") @@ -346,7 +349,7 @@ encoding = parameters.get("ENCODING") charset = parameters.get("CHARSET") - value = self.decode_content(value) + value = self.decode_content(name, value) if encoding == "QUOTED-PRINTABLE": return unicode(quopri.decodestring(value), charset or "iso-8859-1") @@ -582,7 +585,7 @@ elif encoding == "BASE64": value = base64.encodestring(value) - return self.encode_content(value) + return self.encode_content(name, value) except TypeError: raise WriteError, "Property %r value with parameters %r cannot be encoded: %r" % (name, parameters, value) @@ -609,9 +612,9 @@ return encoded_parameters - def encode_content(self, value): + def encode_content(self, name, value): - "Encode the given 'value', quoting characters." + "Encode for property 'name' the given 'value', quoting characters." return (value or "").replace("\n", "\\n")