Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/icalendar/config.py: 44%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

9 statements  

1"""Runtime configuration for icalendar.""" 

2 

3MAX_ALARM_REPEAT: int = 10_000 

4"""Cap on additional triggers expanded from a ``VALARM`` ``REPEAT`` property. 

5 

6:rfc:`5545#section-3.8.6.2` defines ``REPEAT`` as an ``INTEGER`` data type, which is 

7defined in :rfc:`5545#section-3.3.8` as an integer between -2147483648 and 2147483647. 

8A value for ``REPEAT`` that is greater than approximately ``10_000`` can exhaust memory 

9or CPU. The default value of ``10_000`` is a practical setting, but may be adjusted to 

10specific use cases. Set to ``-1`` to disable the cap, which should be done only for 

11fully trusted input. 

12 

13.. versionadded:: 7.2.1 

14""" 

15 

16 

17def _clamp_repeat(n: int) -> int: 

18 """Return *n* clamped to ``[0, MAX_ALARM_REPEAT]``. 

19 

20 Negative values are treated as 0. When :data:`MAX_ALARM_REPEAT` is ``-1`` 

21 the value is returned unchanged after clamping negatives to 0. 

22 """ 

23 if n < 0: 

24 return 0 

25 if MAX_ALARM_REPEAT < 0: 

26 return n 

27 return min(n, MAX_ALARM_REPEAT)