Skip filters with three levels of comp-filter

This commit is contained in:
Unrud 2017-08-30 18:03:40 +02:00
parent 773e4cfca4
commit cfb9b1fc0a

View File

@ -153,10 +153,10 @@ def _date_to_datetime(date_):
return date_ return date_
def _comp_match(item, filter_, scope="collection"): def _comp_match(item, filter_, level=0):
"""Check whether the ``item`` matches the comp ``filter_``. """Check whether the ``item`` matches the comp ``filter_``.
If ``scope`` is ``"collection"``, the filter is applied on the If ``level`` is ``0``, the filter is applied on the
item's collection. Otherwise, it's applied on the item. item's collection. Otherwise, it's applied on the item.
See rfc4791-9.7.1. See rfc4791-9.7.1.
@ -166,10 +166,14 @@ def _comp_match(item, filter_, scope="collection"):
# TODO: Filtering VALARM and VFREEBUSY is not implemented # TODO: Filtering VALARM and VFREEBUSY is not implemented
# HACK: the filters are tested separately against all components # HACK: the filters are tested separately against all components
if scope == "collection": if level == 0:
tag = item.name tag = item.name
else: elif level == 1:
tag = item.component_name tag = item.component_name
else:
item.collection.logger.warning(
"Filters with three levels of comp-filter are not supported")
return True
if not tag: if not tag:
return False return False
name = filter_.get("name").upper() name = filter_.get("name").upper()
@ -186,7 +190,7 @@ def _comp_match(item, filter_, scope="collection"):
item.collection.logger.warning("Filtering %s is not supported" % name) item.collection.logger.warning("Filtering %s is not supported" % name)
return True return True
# Point #3 and #4 of rfc4791-9.7.1 # Point #3 and #4 of rfc4791-9.7.1
components = ([item.item] if scope == "collection" components = ([item.item] if level == 0
else list(getattr(item, "%s_list" % tag.lower()))) else list(getattr(item, "%s_list" % tag.lower())))
for child in filter_: for child in filter_:
if child.tag == _tag("C", "prop-filter"): if child.tag == _tag("C", "prop-filter"):
@ -197,7 +201,7 @@ def _comp_match(item, filter_, scope="collection"):
if not _time_range_match(item.item, filter_[0], tag): if not _time_range_match(item.item, filter_[0], tag):
return False return False
elif child.tag == _tag("C", "comp-filter"): elif child.tag == _tag("C", "comp-filter"):
if not _comp_match(item, child, scope="component"): if not _comp_match(item, child, level=level + 1):
return False return False
else: else:
raise ValueError("Unexpected %r in comp-filter" % child.tag) raise ValueError("Unexpected %r in comp-filter" % child.tag)