Move Item to utils

This commit is contained in:
Markus Unterwaditzer 2014-06-11 18:09:01 +02:00
parent 7d26f7f8fd
commit 41848b2432
2 changed files with 35 additions and 33 deletions

View file

@ -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):

View file

@ -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: