diff --git a/news/656.feature.3 b/news/656.feature.3 new file mode 100644 index 000000000..6209f20be --- /dev/null +++ b/news/656.feature.3 @@ -0,0 +1 @@ +Added the ``DERIVED`` property parameter from :rfc:`9073#section-5.3` (Event Publishing Extensions to iCalendar). It is available on anyproperty (such as :class:`~icalendar.prop.text.vText`) to mark that its value is computed from other properties and must not be edited directly.I used Claude AI (Sonnet 5.5) to assist me with this change.@Mrbozz \ No newline at end of file diff --git a/src/icalendar/param.py b/src/icalendar/param.py index bca86330f..a519189e3 100644 --- a/src/icalendar/param.py +++ b/src/icalendar/param.py @@ -838,12 +838,27 @@ def _del_GAP(prop): # noqa: N802 GAP = property(_get_GAP, _set_GAP, _del_GAP) +DERIVED = boolean_parameter("DERIVED", False) +"""Indicate that a property's value is derived from other property values. + +Conformance: + This property parameter is specified in :rfc:`9073#section-5.3`. + + This parameter MAY be specified on any property whose value can be + derived from the value of one or more other properties. When set to + ``TRUE``, clients MUST NOT update the property's value directly, since + it is expected to be recomputed from the properties it derives from. + The default, when absent, is ``FALSE``. +""" + + __all__ = [ "ALTREP", "CN", "CUTYPE", "DELEGATED_FROM", "DELEGATED_TO", + "DERIVED", "DIR", "EMAIL", "FBTYPE", diff --git a/src/icalendar/prop/text.py b/src/icalendar/prop/text.py index 3c4e7f5c1..4991aa62a 100644 --- a/src/icalendar/prop/text.py +++ b/src/icalendar/prop/text.py @@ -173,7 +173,7 @@ def ical_value(self) -> str: """The string value of the text.""" return str(self) - from icalendar.param import ALTREP, GAP, LANGUAGE, RELTYPE, VALUE + from icalendar.param import ALTREP, DERIVED, GAP, LANGUAGE, RELTYPE, VALUE def to_jcal(self, name: str) -> list: """The jCal representation of this property according to :rfc:`7265`.""" diff --git a/src/icalendar/tests/prop/test_derived_param.py b/src/icalendar/tests/prop/test_derived_param.py new file mode 100644 index 000000000..14d1f4df6 --- /dev/null +++ b/src/icalendar/tests/prop/test_derived_param.py @@ -0,0 +1,25 @@ +r"""DERIVED property parameter from :rfc:`9073`. + +:rfc:`9073#section-5.3` defines DERIVED to mark that a property's value was +computed from other property values and so MUST NOT be edited directly. +The RFC's own example is a STYLED-DESCRIPTION rendering generated from +another STYLED-DESCRIPTION -- a value type not implemented in this codebase +yet (see :issue:`656`). Exercised here on :class:`~icalendar.prop.text.vText` +instead, since DERIVED may be specified on any property. +""" + +from icalendar import vText + + +def test_derived_default_is_false(): + """DERIVED defaults to False when absent, per RFC 9073 5.3.""" + comment = vText("Generated summary") + assert comment.DERIVED is False + + +def test_derived_round_trips_as_bool(): + """Setting DERIVED to True serializes as DERIVED=TRUE and reads back True.""" + comment = vText("Generated summary") + comment.DERIVED = True + assert comment.DERIVED is True + assert comment.params["DERIVED"] == "TRUE"