Bound calendar recurrence expansion and retain MQTT license

This commit is contained in:
Pigway
2026-10-08 23:52:06 +08:00
parent 8209aadbb8
commit 32229609c9
4 changed files with 94 additions and 3 deletions
+12
View File
@@ -44,3 +44,15 @@ terms. This service is not affiliated with Open-Meteo.
## Classical poetry ## Classical poetry
The offline daily-poetry catalog contains original Chinese texts of 20 classical poems by historical authors, in the public domain. No copyrighted modern translations or annotations are included. Selection and rendering are original Frame Flow code and do not reproduce KoKonna subscription content or software. The offline daily-poetry catalog contains original Chinese texts of 20 classical poems by historical authors, in the public domain. No copyrighted modern translations or annotations are included. Selection and rendering are original Frame Flow code and do not reproduce KoKonna subscription content or software.
## Optional MQTT and calendar integrations
Eclipse Paho MQTT Python 2.1.0 is distributed under the Eclipse Public License 2.0
and Eclipse Distribution License 1.0 (BSD 3-Clause), as stated in its bundled
`paho_mqtt-2.1.0.dist-info/licenses/LICENSE.txt`. The dependency's installed license
is retained in the Docker image; the complete EDL text is also included at
`vendor/paho-mqtt-EDL-1.0.txt` (from upstream tag v2.1.0). Source: https://github.com/eclipse-paho/paho.mqtt.python .
python-dateutil 2.9.0.post0 supplies bounded recurrence expansion and is already
pinned in requirements.lock; its bundled upstream license remains with the installed
package. Frame Flow calendar parsing and integration code are independently implemented.
+20 -2
View File
@@ -50,6 +50,12 @@ def calendar_events(raw, now=None):
for props, start, uid, override in parsed: for props, start, uid, override in parsed:
if props.get("STATUS", [(None, "")])[0][1] == "CANCELLED": if props.get("STATUS", [(None, "")])[0][1] == "CANCELLED":
continue continue
if "EXRULE" in props:
raise FlowError(
E.UNSUPPORTED_CAPABILITY,
"Use EXDATE instead of unsupported EXRULE",
422,
)
occurrences = [start] occurrences = [start]
if "RRULE" in props and not override: if "RRULE" in props and not override:
rule = props["RRULE"][0][1] rule = props["RRULE"][0][1]
@@ -63,8 +69,20 @@ def calendar_events(raw, now=None):
raise FlowError( raise FlowError(
E.INVALID_REQUEST, "Calendar recurrence starts too far in the past" E.INVALID_REQUEST, "Calendar recurrence starts too far in the past"
) )
occurrences = rrulestr(rule, dtstart=start).between( if len(rule) > 1000:
now - timedelta(days=1), end, inc=True raise FlowError(
E.INVALID_REQUEST, "Calendar recurrence rule is too long"
)
occurrences = []
for occurrence in rrulestr(rule, dtstart=start).xafter(
now - timedelta(days=1), count=1001, inc=True
):
if occurrence >= end:
break
occurrences.append(occurrence)
if len(occurrences) > 1000:
raise FlowError(
E.INVALID_REQUEST, "Calendar recurrence exceeds 1000 instances"
) )
for key, value in props.get("RDATE", []): for key, value in props.get("RDATE", []):
occurrences.extend(stamp(key, item) for item in value.split(",")) occurrences.extend(stamp(key, item) for item in value.split(","))
+30
View File
@@ -58,3 +58,33 @@ def test_timezone_and_past_filter():
)["events"] )["events"]
== [] == []
) )
def test_dense_recurrence_is_bounded():
rule = (
"FREQ=DAILY;BYHOUR="
+ ",".join(map(str, range(24)))
+ ";BYMINUTE="
+ ",".join(map(str, range(60)))
)
with pytest.raises(FlowError):
calendar_events(
feed("DTSTART:20261008T000000Z\r\nRRULE:" + rule + "\r\nSUMMARY:Too many"),
datetime(2026, 10, 8, tzinfo=UTC),
)
def test_exrule_not_silently_ignored():
with pytest.raises(FlowError):
calendar_events(
feed("DTSTART:20261008T080000Z\r\nEXRULE:FREQ=DAILY\r\nSUMMARY:Excluded"),
datetime(2026, 10, 8, tzinfo=UTC),
)
def test_all_day_today_in_local_timezone():
result = calendar_events(
feed("DTSTART;VALUE=DATE:20261008\r\nSUMMARY:Today"),
datetime(2026, 10, 8, 1, tzinfo=UTC),
)
assert len(result["events"]) == 1
+31
View File
@@ -0,0 +1,31 @@
Eclipse Distribution License - v 1.0
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of the Eclipse Foundation, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.