Use vobject.iCalendar as template for calendar serialization

This commit is contained in:
Unrud 2017-09-06 00:20:42 +02:00
parent f3c368e547
commit 8e53434912

View File

@ -671,32 +671,28 @@ class BaseCollection:
if depth == 1 and line.startswith("END:"): if depth == 1 and line.startswith("END:"):
in_vcalendar = False in_vcalendar = False
if depth == 2 and line == "BEGIN:VTIMEZONE": if depth == 2 and line == "BEGIN:VTIMEZONE":
vtimezone.append(line) vtimezone.append(line + "\r\n")
elif vtimezone: elif vtimezone:
vtimezone.append(line) vtimezone.append(line + "\r\n")
if depth == 2 and line.startswith("TZID:"): if depth == 2 and line.startswith("TZID:"):
tzid = line[len("TZID:"):] tzid = line[len("TZID:"):]
elif depth == 2 and line.startswith("END:"): elif depth == 2 and line.startswith("END:"):
if tzid is None or tzid not in included_tzids: if tzid is None or tzid not in included_tzids:
if vtimezones: vtimezones += "".join(vtimezone)
vtimezones += "\r\n"
vtimezones += "\r\n".join(vtimezone)
included_tzids.add(tzid) included_tzids.add(tzid)
vtimezone.clear() vtimezone.clear()
tzid = None tzid = None
elif depth >= 2: elif depth >= 2:
if components: components += line + "\r\n"
components += "\r\n"
components += line
if line.startswith("END:"): if line.startswith("END:"):
depth -= 1 depth -= 1
return "\r\n".join(filter(bool, ( template = vobject.iCalendar()
"BEGIN:VCALENDAR", template = template.serialize()
"VERSION:2.0", template_insert_pos = template.find("\r\nEND:VCALENDAR\r\n") + 2
"PRODID:-//PYVOBJECT//NONSGML Version 1//EN", assert template_insert_pos != -1
vtimezones, return (template[:template_insert_pos] +
components, vtimezones + components +
"END:VCALENDAR"))) template[template_insert_pos:])
elif self.get_meta("tag") == "VADDRESSBOOK": elif self.get_meta("tag") == "VADDRESSBOOK":
return "".join((item.serialize() for item in self.get_all())) return "".join((item.serialize() for item in self.get_all()))
return "" return ""