Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 23 additions & 39 deletions AI-POLICY.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,36 @@
# Policy on usage of Artificial Intelligence and other tools
# New policy on usage of Artificial Intelligence and other tools

This project receives funding from [NLnet](https://nlnet.nl/), and has
done so since before NLnet introduced a GenAI policy. Now NLnet has published a [Version
2.0](https://nlnet.nl/foundation/policies/generativeAI/2.0/) of their policy.

**Starting from 2026-12-04 I will adhere to this policy and stop allowing AI-generated contributions to this project**. One exception: if you're struck by a serious bug and have a PR that solves the problem for you, I will consider merging it.

This policy will be evaluated in February. I do believe that AI-generation has been useful to this project. It may be that it's better for the project to forego the funding and keep vibing on - but I will decide on that later.

# Old policy on usage of Artificial Intelligence and other tools

This policy applies until 2026-12-04, and possibly after an evaluation in 2027-02.

## Read this first

The most important rule: be honest and inform about it! The
second-most important rule: YOU should add value to the project. That
value may be to find and reproduce a bug and verify that an
AI-generated fix solves the issue.
The most important rules:

If you ask the AI to "find some low-hanging fruit in the issue tracker
and generate a PR", then you're not adding value to the project. The
maintainer can probably do that himself, with a better overview of
what needs to be prioritized. Reviewing an AI-generated PR often
takes the maintainer more effort than doing the work directly.
1. You should (as a human) **write some sentences about why it's important for you** to get the PR approved.
2. **Be honest and inform about AI-usage.**
3. YOU should add value to the project. That value may be to find and
reproduce a bug and verify that an AI-generated fix solves the issue.

Keep a log of the prompts and/or commands used - this should be
included verbatim in the git commits as long as it's possible
**Prompts should be included verbatim in the git commits** as long as it's possible
without making the messages too messy. When relevant, chat-output may
also need to be included or paraphrased. The `docs/design`-folder can
be used for dumping AI-generated design documents, code reviews,
prompts that are too large for being included in the commit message,
etc.
also need to be included. If that doesn't work out, then at least deliver the prompts paraphrased.

The `docs/design`-folder can be used for dumping AI-generated design documents, code reviews, prompts that are too large for being included in the commit message, etc.

If you think the rest of the document is too long to read, at least
ask the AI to ensure the policy is followed. "YOU" in this
document means the human, not the AI.

## NLnet funding and its GenAI policy

This project receives funding from [NLnet](https://nlnet.nl/), and has
done so since before NLnet introduced a GenAI policy. The project is
currently committed to [version
1.1](https://nlnet.nl/foundation/policies/generativeAI/1.1/) of that
policy, which allows GenAI-assisted work as long as it is disclosed and
logged, and this document is written to fit it. [Version
2.0](https://nlnet.nl/foundation/policies/generativeAI/2.0/) of
2026-10-20 only allows GenAI to be used in a read-only manner (code
review, for instance), and NLnet wants it adopted. This document will
have to be revised if the project continues to receive NLnet funding.
Until that is settled, the rules below apply to all contributions.

The priority is to deliver a good, feature-complete, easy-to-use and
bug-free library that stays compatible with as many servers as possible.
NLnet funding makes it possible for me to prioritize this, and spend
some hours a week rather than some hours a month on this project.
However, as the AI-models keep improving it may be questioned whether a
few hours a month of unfunded "vibe engineering" is of higher
value than a few hours a week of funded manual human labour.

## Transparency matters

If you've spent hours, perhaps a full day of your time writing up a
Expand Down Expand Up @@ -145,7 +129,7 @@ Before I started to use the AI, I was aiming for "logical" commits containing in

## Future plans of GenAI-usage

I do want to go back to the old ways for doing the "core development tasks" - new features and complex refactoring. If nothing else, it's important for maintaining my brain cells, coding skills and making sure all the changes stick to my memory. The new policy is that GenAI-tools should be used mainly for improving quality, not speeding up the development. However, as my brain apparently has continued rotting due to extensive AI-usage, combined with improved models, I haven't been able to get back to "the old ways".
I do want to go back to the old ways for doing the "core development tasks" - new features and complex refactoring. If nothing else, it's important for maintaining my brain cells, coding skills and making sure all the changes stick to my memory. My own policy is that GenAI-tools should be used mainly for improving quality, not speeding up the development. However, as my brain apparently has continued rotting due to extensive AI-usage, combined with improved models, I haven't been able to get back to "the old ways".

GenAI is very well suited for certain tasks, particularly anything that is either "mundane and tedious" or unrelated to "the working end" of the library. Examples:

Expand Down
25 changes: 19 additions & 6 deletions caldav/async_davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,25 +991,38 @@ async def get_calendars(self, principal: Optional["Principal"] = None) -> list["
props=self.CALENDAR_HOME_SET_PROPS,
depth=0,
)
# Fetch calendars via PROPFIND, from the first URL that has any
# Fetch calendars via PROPFIND: from every home the server lists,
# or else from the first guessed URL that has any
calendar_home_urls, listed = self._calendar_home_urls(response, principal)
calendars = []
for n, calendar_home_url in enumerate(self._calendar_home_urls(response, principal)):
for n, calendar_home_url in enumerate(calendar_home_urls):
auth = (self.auth, self.auth_type)
try:
response = await self.propfind(
calendar_home_url,
props=self.CALENDAR_LIST_PROPS,
depth=1,
)
found = self._build_calendars_from_propfind(response, guess=n > 0 and not listed)
except error.AuthorizationError:
# a refused guess means no calendars there; keep the auth
# that worked so far, which the refusal may have unwound
# a refused guess, or a refused extra home, means no
# calendars there; keep the auth that worked so far,
# which the refusal may have unwound
if not n:
raise
self.auth, self.auth_type = auth
if listed:
continue
break
calendars = self._build_calendars_from_propfind(response, guess=n > 0)
if calendars:
except error.DAVError as e:
# an extra home the server lists may be gone (a revoked
# share); that must not cost the user their own calendars
if not (n and listed):
raise
log.warning(f"skipping calendar home {calendar_home_url}: {e}")
continue
calendars.extend(found)
if found and not listed:
break
return calendars

Expand Down
38 changes: 26 additions & 12 deletions caldav/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,28 +600,42 @@ def _rate_limit_sleep_seconds(
# Pure result-handling shared by sync/async get_calendars; only the two
# awaited PROPFIND calls and the principal lookup differ between the twins.

def _calendar_home_urls(self, home_set_response: Any, principal: Any) -> list[str]:
"""Return absolute URLs to search for calendars, in order of preference.

Without a calendar-home-set, try the principal URL, then the
client URL, which may be a calendar itself (e.g. Nextcloud public share).
def _calendar_home_urls(self, home_set_response: Any, principal: Any) -> tuple[list[str], bool]:
"""Return absolute URLs to search for calendars, and whether they are listed.

The URLs the server lists in calendar-home-set (RFC 4791 section
6.2.1 allows several; Stalwart gives one per account sharing
calendars, ref https://github.com/python-caldav/caldav/issues/888)
are authoritative, and the calendars under all of them belong in the
answer. Without a calendar-home-set, the principal URL and then the
client URL, which may be a calendar itself (e.g. Nextcloud public
share), are guesses: the first one holding any calendars wins.
The client root is moved to the host of the first URL, if it differs.
"""
from caldav.collection import (
_extract_calendar_home_set_from_results as extract_home_set,
)
from caldav.collection import _extract_calendar_home_sets_from_results

_raise_unless_propfind_ok(home_set_response)
calendar_home_url = extract_home_set(home_set_response.results, features=self.features)
if calendar_home_url:
urls = [self._make_absolute_url(calendar_home_url)]
home_sets = _extract_calendar_home_sets_from_results(
home_set_response.results, features=self.features
)
listed = bool(home_sets)
if listed:
## once each: a server may list one home in two spellings
urls = []
seen = set()
for home_set in home_sets:
url = self._make_absolute_url(home_set)
key = URL.objectify(url).canonical()
if key not in seen:
seen.add(key)
urls.append(url)
else:
urls = [self._make_absolute_url(str(principal.url))]
canonical = URL.objectify(urls[0]).canonical().strip_trailing_slash()
if canonical != self.url.canonical().strip_trailing_slash():
urls.append(str(self.url))
self._follow_calendar_home(urls[0])
return urls
return urls, listed

def _follow_calendar_home(self, calendar_home_url: Any) -> None:
"""Move the client root to the host of the calendar-home-set.
Expand Down
73 changes: 18 additions & 55 deletions caldav/calendarobjectresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,6 @@ def _find_id_path(self, id=None, path=None) -> None:

def _put(
self,
retry_on_failure=True,
precondition: Precondition = "auto",
wildcard: Wildcard | None = None,
) -> "None | Coroutine[Any, Any, None]":
Expand All @@ -1240,13 +1239,11 @@ def _put(
## The server drops a task's DTSTART unless it has a DUE (Zimbra)
body = vcal.duration_as_due(str(body))
if self.is_async_client:
return self._async_send_put(
str(body), headers, retry_on_failure, precondition, wildcard
)
return self._send_put(body, headers, retry_on_failure, precondition, wildcard)
return self._async_send_put(str(body), headers, precondition, wildcard)
return self._send_put(body, headers, precondition, wildcard)

def _send_put(
self, body, headers, retry_on_failure, precondition: Precondition, wildcard: Wildcard | None
self, body, headers, precondition: Precondition, wildcard: Wildcard | None
) -> None:
"""The PUT of ``_put()`` and ``_put_raw()``, with what the answer
says about a UID conflict (``_raise_uid_conflict``,
Expand All @@ -1257,7 +1254,7 @@ def _send_put(
self._raise_uid_conflict(e, wildcard is not None)
raise
try:
return self._post_put(r, retry_on_failure, precondition, wildcard)
return self._post_put(r, precondition, wildcard)
except error.DAVError as e:
if not isinstance(e, error.UidConflictError) and self._bare_uid_conflict(
e.status, precondition, wildcard
Expand All @@ -1266,18 +1263,15 @@ def _send_put(
raise

async def _async_send_put(
self, body, headers, retry_on_failure, precondition: Precondition, wildcard: Wildcard | None
self, body, headers, precondition: Precondition, wildcard: Wildcard | None
) -> None:
try:
r = await self.client.put(str(self.url), body, headers)
except error.AuthorizationError as e:
self._raise_uid_conflict(e, wildcard is not None)
raise
try:
result = self._post_put(r, retry_on_failure, precondition, wildcard)
if result is not None:
# _post_put returned a retry coroutine (self._put(False) for async client)
await result
self._post_put(r, precondition, wildcard)
except error.DAVError as e:
if not isinstance(e, error.UidConflictError) and self._bare_uid_conflict(
e.status, precondition, wildcard
Expand Down Expand Up @@ -1591,10 +1585,9 @@ async def _async_get_status(self, url) -> int | None:
def _post_put(
self,
r,
retry_on_failure,
precondition: Precondition = "auto",
wildcard: Wildcard | None = None,
) -> "None | Coroutine[Any, Any, None]":
) -> None:
if r.status >= 400:
## The UID is taken (RFC 4791 section 5.3.2.1): not something a
## retry would fix (issue #756). A 412 on a conditional save
Expand Down Expand Up @@ -1636,36 +1629,11 @@ def _post_put(
## 15.4.4) - presumably the object, under a name of the server's
self.url = self.url.relocate(urljoin(str(self.url), r.headers["Location"]))
elif r.status not in (200, 201, 204):
## No retry with a wildcard: an object this very PUT may have
## stored (a 5xx after writing) would refuse If-None-Match: *,
## and the failure is reported as it was for If-Match: * too.
## Nor where it may be a taken UID: cleaning up the data does not free it.
## A 5xx may also follow a successful write; retrying could mask
## that uncertain outcome with a refusal from the second PUT.
## Nor a redirect the client did not follow (another host or
## port): nothing was stored, and another PUT is redirected too.
if (
wildcard
or 300 <= r.status < 400
or r.status >= 500
or self._bare_uid_conflict(r.status, precondition, wildcard)
):
retry_on_failure = False
if retry_on_failure:
try:
import vobject # noqa: F401
except ImportError:
retry_on_failure = False
if retry_on_failure:
## Accessing vobject_instance may "clean" the object.
## See https://github.com/python-caldav/caldav/issues/43
try:
self.get_vobject_instance()
except vobject.base.ParseError as exc:
raise error.error_from_response(error.PutError, r) from exc
return self._put(False, precondition, wildcard)
else:
raise error.error_from_response(error.PutError, r)
## Not retried: the second PUT would send the same bytes, a 5xx
## may follow a successful write, and only the second answer
## would reach the caller, ref
## https://github.com/python-caldav/caldav/issues/847
raise error.error_from_response(error.PutError, r)
if isinstance(getattr(r, "redirected_to", None), URL):
## Stored at the Location of a redirect (Zimbra: <uid>.ics)
self.url = self.url.relocate(r.redirected_to)
Expand All @@ -1677,10 +1645,7 @@ def _post_put(
def _put_raw(
self, body: bytes, precondition: Precondition = "auto", wildcard: Wildcard | None = None
) -> "None | Coroutine[Any, Any, None]":
"""PUT ``body`` unchanged, for ``save(raw_data=...)``.

Unlike ``_put()``, a failure is not retried with a cleaned-up
copy of the data: the caller asked for exactly these bytes."""
"""PUT ``body`` unchanged, for ``save(raw_data=...)``."""
if self.url is None:
if not self.id:
raise ValueError(
Expand All @@ -1691,8 +1656,8 @@ def _put_raw(
headers = self._put_headers(precondition, wildcard)
body = WireBytes(body)
if self.is_async_client:
return self._async_send_put(body, headers, False, precondition, wildcard)
return self._send_put(body, headers, False, precondition, wildcard)
return self._async_send_put(body, headers, precondition, wildcard)
return self._send_put(body, headers, precondition, wildcard)

@staticmethod
def _check_raw_data(raw_data: Any) -> bytes | None:
Expand Down Expand Up @@ -1722,25 +1687,23 @@ def _create(
self,
id=None,
path=None,
retry_on_failure=True,
precondition: Precondition = "auto",
wildcard: Wildcard | None = None,
) -> "None | Coroutine[Any, Any, None]":
## TODO: Find a better method name
self._find_id_path(id=id, path=path)
if self.is_async_client:
return self._async_create(retry_on_failure, precondition, wildcard)
self._put(retry_on_failure, precondition, wildcard)
return self._async_create(precondition, wildcard)
self._put(precondition, wildcard)
return None

async def _async_create(
self,
retry_on_failure=True,
precondition: Precondition = "auto",
wildcard: Wildcard | None = None,
) -> None:
"""Async implementation of _create."""
await self._put(retry_on_failure, precondition, wildcard)
await self._put(precondition, wildcard)

def _generate_url(self):
## See https://github.com/python-caldav/caldav/issues/143 for the rationale behind double-quoting slashes
Expand Down
Loading
Loading