From 41848b24326d85d18b6e03d38e8406f7ce75c30b Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 11 Jun 2014 18:09:01 +0200 Subject: [PATCH] Move Item to utils --- vdirsyncer/storage/base.py | 34 +--------------------------------- vdirsyncer/utils/vobject.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/vdirsyncer/storage/base.py b/vdirsyncer/storage/base.py index e85b8f2..1aafdf7 100644 --- a/vdirsyncer/storage/base.py +++ b/vdirsyncer/storage/base.py @@ -10,41 +10,9 @@ from .. import exceptions from .. import utils -from ..utils.compat import text_type -class Item(object): - - '''should-be-immutable wrapper class for VCALENDAR (VEVENT, VTODO) and - VCARD''' - - uid = None - '''Global identifier of the item, across storages, doesn't change after a - modification of the item.''' - - raw = None - '''Raw content of the item, which vdirsyncer doesn't validate in any - way.''' - - hash = None - '''Hash of self.raw, used for etags.''' - - ident = None - '''Used for generating hrefs and matching up items during synchronization. - This is either the UID or the hash of the item's content.''' - - def __init__(self, raw): - assert isinstance(raw, text_type) - - for line in raw.splitlines(): - if line.startswith(u'UID:'): - uid = line[4:].strip() - if uid: - self.uid = uid - - self.raw = raw - self.hash = utils.vobject.hash_item(raw) - self.ident = self.uid or self.hash +Item = utils.vobject.Item class Storage(object): diff --git a/vdirsyncer/utils/vobject.py b/vdirsyncer/utils/vobject.py index 8ffd4b2..13cea8d 100644 --- a/vdirsyncer/utils/vobject.py +++ b/vdirsyncer/utils/vobject.py @@ -47,6 +47,40 @@ ICALENDAR_ORIGINAL_ORDER_SUPPORT = \ hasattr(icalendar.caselessdict.CaselessDict, '__reversed__') +class Item(object): + + '''should-be-immutable wrapper class for VCALENDAR (VEVENT, VTODO) and + VCARD''' + + uid = None + '''Global identifier of the item, across storages, doesn't change after a + modification of the item.''' + + raw = None + '''Raw content of the item, which vdirsyncer doesn't validate in any + way.''' + + hash = None + '''Hash of self.raw, used for etags.''' + + ident = None + '''Used for generating hrefs and matching up items during synchronization. + This is either the UID or the hash of the item's content.''' + + def __init__(self, raw): + assert isinstance(raw, text_type) + + for line in raw.splitlines(): + if line.startswith(u'UID:'): + uid = line[4:].strip() + if uid: + self.uid = uid + + self.raw = raw + self.hash = hash_item(raw) + self.ident = self.uid or self.hash + + def normalize_item(text, ignore_props=IGNORE_PROPS, use_icalendar=True): try: if not use_icalendar: