From a4a52c71d2c08b828e87ab0e854c4703adac2889 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 6 Jan 2012 19:42:20 +0100 Subject: [PATCH] Use a clean way to manage calendars and address books different serialization --- radicale/ical.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/radicale/ical.py b/radicale/ical.py index 6072bb2..c16c506 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -47,13 +47,17 @@ def open(path, mode="r"): # pylint: enable=W0622 -def serialize(tag, headers=(), items=()): - """Return a collection text corresponding to given ``tag``. +def serialize(tag, headers=(), items=(), whole=False): + """Return a text corresponding to given collection ``tag``. - The collection has the given ``headers`` and ``items``. + The text may have the given ``headers`` and ``items`` added around the + items if needed (ie. for calendars). + + If ``whole`` is ``True``, the collection tags and headers are added, even + for address books. """ - if tag == "VCARD" or (tag == "VADDRESSBOOK" and items and len(items) == 1): + if tag == "VADDRESSBOOK" and not whole: lines = [items[0].text] else: lines = ["BEGIN:%s" % tag] @@ -382,7 +386,7 @@ class Collection(object): self._create_dirs(self.path) - text = serialize(self.tag, headers, items) + text = serialize(self.tag, headers, items, True) return open(self.path, "w").write(text) def set_mimetype(self, mimetype):