From 087312adb54d3622af0dab630ed3ea06e428f3e3 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 2 May 2014 18:17:50 +0200 Subject: [PATCH] Stricter validation of items --- vdirsyncer/storage/base.py | 6 +++++- vdirsyncer/storage/http.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vdirsyncer/storage/base.py b/vdirsyncer/storage/base.py index 028a3e4..624a69f 100644 --- a/vdirsyncer/storage/base.py +++ b/vdirsyncer/storage/base.py @@ -15,7 +15,7 @@ class Item(object): '''should-be-immutable wrapper class for VCALENDAR and VCARD''' - def __init__(self, raw): + def __init__(self, raw, needs_uid=True): assert isinstance(raw, utils.text_type) raw = raw.splitlines() self.uid = None @@ -23,6 +23,10 @@ class Item(object): for line in raw: if line.startswith(u'UID:'): self.uid = line[4:].strip() + + if needs_uid and self.uid is None: + raise ValueError('Item has not uid.') + self.raw = u'\n'.join(raw) diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index 65818ff..ccc7517 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -50,7 +50,7 @@ def split_collection(text): item.extend(timezone) item.append(line) if item_type != u'VTIMEZONE': - yield Item(u'\n'.join(item)) + yield Item(u'\n'.join(item), needs_uid=False) item = [] item_type = None else: