Skip to content

Commit 848a82c

Browse files
committed
More deprecations
The `expand` parameter should be a bool. From 1.4, "client" and "server" was accepted. This have been moved into a new parameter `server_expand`. `server_expand` is by default False, used to be True if expand was True.
1 parent 4f9b489 commit 848a82c

2 files changed

Lines changed: 52 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ This project should adhere to [Semantic Versioning](https://semver.org/spec/v2.0
1515

1616
### Added
1717

18-
* `event.component` is now an alias for `event.icalendar_component`
18+
* `event.component` is now an alias for `event.icalendar_component`.
1919

2020
### Changed
2121

2222
* The request library has been in a feature freeze for ages and may seem like a dead end. There exists a fork of the project niquests, we're migrating to that one. This means nothing except for one additional dependency. (httpx was also considered, but it's not a drop-in replacement for the requests library, and it's a risk that such a change will break compatibility with various other servers - see https://github.com/python-caldav/caldav/issues/457 for details). Work by @ArtemIsmagilov, https://github.com/python-caldav/caldav/pull/455.
23+
* Search has a new parameter server_expand, which defaults to False. Earlier it would default to True if expand was set. This change makes `search(expand=True, ...)` more consistent regardless of which server is in use, but it breaks bug-backward-compatibility with 1.x.
2324

2425
### Removed
2526

caldav/collection.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ def search(
741741
sort_keys: Sequence[str] = (),
742742
sort_reverse: bool = False,
743743
expand: Union[bool, Literal["server"], Literal["client"]] = False,
744+
server_expand: bool = False,
744745
split_expanded: bool = True,
745746
props: Optional[List[cdav.CalendarData]] = None,
746747
**kwargs,
@@ -755,10 +756,32 @@ def search(
755756
and client side filtering to make sure other search results
756757
are consistent on different server implementations.
757758
758-
LEGACY WARNING: the expand attribute currently takes four
759-
possible values - True, False, server and client. The two
760-
latter value were hastily added just prior to launching
761-
version 1.4, the API may be reconsidered at some point.
759+
expand can only be set to True for closed date searches - but
760+
unless you know what you're doing, it's recommended to ask for
761+
expanded recurrences. Without expand, be prepared that you
762+
may get back events that apparently has a DTSTART/DTEND that
763+
does not match the search interval, and you may also get back
764+
objects containing multiple components (and this may break
765+
when using `icalendar_component` as recommended, like
766+
`event.icalendar_component['summary']) may disregard that the
767+
summary has been modified for future events.
768+
769+
Only True or False should be given to expand. Client-side
770+
expansion is now the default. Server-side expansion can be
771+
set by setting `server_expand=True`. If both `server_expand`
772+
and `expand` is set, there will be a fallback to client-side
773+
expansion if needed.
774+
775+
The CalDAV server usually delivers one VCALENDAR for each
776+
component (i.e. event) found, this is again expanded to a
777+
list. The exception is for recurrences (either expanded
778+
recurrences or exceptions to the rule) - a VCALENDAR
779+
containing all the recurrences are passed. The caller most
780+
likely wants one list item for each recurrence, hence
781+
`split_expanded` is set to True by default. If you set it to
782+
False (and expand to True), a recurring event with many
783+
recurrences will be delivered as one list item containing a
784+
VCALENDAR with many components.
762785
763786
Parameters supported:
764787
@@ -775,6 +798,7 @@ def search(
775798
* no-category, no-summary, etc ... search for objects that does not
776799
have those attributes. TODO: WRITE TEST CODE!
777800
* expand - expand recurring objects
801+
* server_expand - ask the server to expand recurring objects
778802
* start, end: do a time range search
779803
* filters - other kind of filters (in lxml tree format)
780804
* sort_keys - list of attributes to use when sorting
@@ -785,6 +809,22 @@ def search(
785809
* attribute not set
786810
787811
"""
812+
if expand not in (True, False):
813+
warnings.warn(
814+
"in cal.search(), expand should be a bool",
815+
DeprecationWarning,
816+
stacklevel=2,
817+
)
818+
if expand == "client":
819+
expand = True
820+
if expand == "server":
821+
server_expand = True
822+
expand = False
823+
824+
if expand or server_expand:
825+
if not kwargs.get("start") or not kwargs.get("end"):
826+
raise error.ReportError("can't expand without a date range")
827+
788828
## special compatibility-case when searching for pending todos
789829
if todo and not include_completed:
790830
matches1 = self.search(
@@ -823,7 +863,7 @@ def search(
823863
objects.append(item)
824864
else:
825865
if not xml:
826-
if expand and expand != "client":
866+
if server_expand:
827867
kwargs["expand"] = True
828868
(xml, comp_class) = self.build_search_xml_query(
829869
comp_class=comp_class, todo=todo, props=props, **kwargs
@@ -851,6 +891,9 @@ def search(
851891
event=True,
852892
include_completed=include_completed,
853893
sort_keys=sort_keys,
894+
sort_reverse=sort_reverse,
895+
expand=expand,
896+
server_expand=server_expand,
854897
split_expanded=split_expanded,
855898
props=props,
856899
**kwargs,
@@ -876,7 +919,7 @@ def search(
876919
## Google sometimes returns empty objects
877920
objects = [o for o in objects if o.has_component()]
878921

879-
if expand and expand != "server":
922+
if expand:
880923
## expand can only be used together with start and end (and not
881924
## with xml). Error checking has already been done in
882925
## build_search_xml_query above.
@@ -896,7 +939,7 @@ def search(
896939
## icalendar data containing multiple objects. The caller may
897940
## expect multiple Event()s. This code splits events into
898941
## separate objects:
899-
if expand and split_expanded:
942+
if (expand or server_expand) and split_expanded:
900943
objects_ = objects
901944
objects = []
902945
for o in objects_:

0 commit comments

Comments
 (0)