mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Refactor IGNORE_PROPS
This commit is contained in:
parent
66031a51e6
commit
5ae2d27b66
1 changed files with 22 additions and 24 deletions
|
|
@ -4,18 +4,14 @@ import hashlib
|
||||||
from itertools import chain, tee
|
from itertools import chain, tee
|
||||||
|
|
||||||
from . import cached_property, uniq
|
from . import cached_property, uniq
|
||||||
from .compat import itervalues, text_type
|
from .compat import itervalues, text_type, to_unicode
|
||||||
|
|
||||||
|
|
||||||
def _process_properties(*s):
|
def _prepare_props(*x):
|
||||||
rv = set()
|
return tuple(map(to_unicode, x))
|
||||||
for key in s:
|
|
||||||
rv.add(key + ':')
|
|
||||||
rv.add(key + ';')
|
|
||||||
|
|
||||||
return tuple(rv)
|
|
||||||
|
|
||||||
IGNORE_PROPS = _process_properties(
|
IGNORE_PROPS = _prepare_props(
|
||||||
# PRODID is changed by radicale for some reason after upload
|
# PRODID is changed by radicale for some reason after upload
|
||||||
'PRODID',
|
'PRODID',
|
||||||
# X-RADICALE-NAME is used by radicale, because hrefs don't really exist in
|
# X-RADICALE-NAME is used by radicale, because hrefs don't really exist in
|
||||||
|
|
@ -24,22 +20,21 @@ IGNORE_PROPS = _process_properties(
|
||||||
# Apparently this is set by Horde?
|
# Apparently this is set by Horde?
|
||||||
# https://github.com/pimutils/vdirsyncer/issues/318
|
# https://github.com/pimutils/vdirsyncer/issues/318
|
||||||
'X-WR-CALNAME',
|
'X-WR-CALNAME',
|
||||||
# REV is from the VCARD specification and is supposed to change when the
|
# Those are from the VCARD specification and is supposed to change when the
|
||||||
# item does -- however, we can determine that ourselves
|
# item does -- however, we can determine that ourselves
|
||||||
# Same with LAST-MODIFIED
|
|
||||||
'REV',
|
'REV',
|
||||||
'LAST-MODIFIED',
|
'LAST-MODIFIED',
|
||||||
'CREATED',
|
'CREATED',
|
||||||
# Added those because e.g. http://www.feiertage-oesterreich.at/ is
|
# Some iCalendar HTTP calendars generate the DTSTAMP at request time, so
|
||||||
# generating those randomly on every request.
|
# this property always changes when the rest of the item didn't. Some do
|
||||||
# Some iCalendar HTTP calendars (Google's read-only calendar links)
|
# the same with the UID.
|
||||||
# generate the DTSTAMP at request time, so this property always changes
|
#
|
||||||
# when the rest of the item didn't.
|
# - Google's read-only calendar links
|
||||||
# Some do the same with the UID.
|
# - http://www.feiertage-oesterreich.at/
|
||||||
'DTSTAMP',
|
'DTSTAMP',
|
||||||
'UID',
|
'UID',
|
||||||
)
|
)
|
||||||
del _process_properties
|
del _prepare_props
|
||||||
|
|
||||||
|
|
||||||
class Item(object):
|
class Item(object):
|
||||||
|
|
@ -102,10 +97,13 @@ def normalize_item(item, ignore_props=IGNORE_PROPS):
|
||||||
'''Create syntactically invalid mess that is equal for similar items.'''
|
'''Create syntactically invalid mess that is equal for similar items.'''
|
||||||
if not isinstance(item, Item):
|
if not isinstance(item, Item):
|
||||||
item = Item(item)
|
item = Item(item)
|
||||||
return u'\r\n'.join(line.strip()
|
|
||||||
for line in sorted(item.raw.splitlines())
|
x = _Component('TEMP', item.raw.splitlines(), [])
|
||||||
if line.strip() and
|
for prop in IGNORE_PROPS:
|
||||||
not line.startswith(IGNORE_PROPS))
|
del x[prop]
|
||||||
|
|
||||||
|
x.props.sort()
|
||||||
|
return u'\r\n'.join(filter(bool, (line.strip() for line in x.props)))
|
||||||
|
|
||||||
|
|
||||||
def hash_item(text):
|
def hash_item(text):
|
||||||
|
|
@ -283,7 +281,7 @@ class _Component(object):
|
||||||
yield u'END:{}'.format(self.name)
|
yield u'END:{}'.format(self.name)
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
prefix = u'{}:'.format(key)
|
prefix = (u'{}:'.format(key), u'{};'.format(key))
|
||||||
new_lines = []
|
new_lines = []
|
||||||
lineiter = iter(self.props)
|
lineiter = iter(self.props)
|
||||||
for line in lineiter:
|
for line in lineiter:
|
||||||
|
|
@ -308,11 +306,11 @@ class _Component(object):
|
||||||
self.props.append(line)
|
self.props.append(line)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
prefix = u'{}:'.format(key)
|
prefix = (u'{}:'.format(key), u'{};'.format(key))
|
||||||
iterlines = iter(self.props)
|
iterlines = iter(self.props)
|
||||||
for line in iterlines:
|
for line in iterlines:
|
||||||
if line.startswith(prefix):
|
if line.startswith(prefix):
|
||||||
rv = line[len(prefix):]
|
rv = line.split(u':', 1)[-1]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise KeyError()
|
raise KeyError()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue