o
    ÌÄ.jå
  ã                   @   sˆ   d Z ddlZddlmZmZ dedefdd„Zej 	dg d¢¡ejj	d	e
egd
dgddd„ ƒƒZej 	dg d¢¡dd„ ƒZdd„ ZdS )a#  Regression test for repr() RecursionError on deeply-nested calendars.

See https://github.com/collective/icalendar/issues/1370.

A crafted ``.ics`` payload of only ~13 KB nesting ``BEGIN:VEVENT``
many levels deep used to make ``repr()`` / ``str()`` / ``f"{cal}"``
raise an uncaught ``RecursionError`` at default recursion limit (1000).

The parser itself is iterative and accepts the input fine; only the
``Component.__repr__`` traversal was recursive. This test exercises both
moderate (default-recursion-limit-breaking) and pathological depths.
é    N)ÚCalendarÚEventÚdepthÚreturnc                 C   sH   g d¢}|dg|  7 }|ddg7 }|dg|  7 }|dg7 }d  |¡d S )z>Return an .ics payload with ``depth`` levels of nested VEVENT.)zBEGIN:VCALENDARzVERSION:2.0zPRODID:-//test//test//ENzBEGIN:VEVENTzUID:nested@example.comzDTSTAMP:20260101T000000Zz
END:VEVENTzEND:VCALENDARz
)Újoin)r   Úlines© r   úX/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_repr_recursion.pyÚ_make_nested_calendar   s   
r
   )é
   éd   éô  éè  ÚfnÚreprÚstr)Úidsc                 C   sL   t |ƒ}t |¡}| |ƒ}| d¡sJ ‚| d¡sJ ‚| d¡|ks$J ‚dS )z¸``repr()`` and ``str()`` must not raise ``RecursionError``
    regardless of nesting depth. ``str()`` falls through to ``__repr__``,
    so the same depths are exercised for both.
    z
VCALENDAR(ú)zVEVENT(N)r
   r   Ú	from_icalÚ
startswithÚendswithÚcount)r   r   ÚicsÚcalÚresultr   r   r	   Ú.test_repr_and_str_do_not_raise_recursion_error   s   
r   )é   é   r   r   r   c                 C   sX   t ƒ }|}t| ƒD ]}tƒ }| |¡ |}q	dd|   d| d   }t|ƒ|ks*J ‚dS )a=  The exact ``repr()`` string matches the format produced by the
    previous (recursive) implementation: ``VCALENDAR({}, VEVENT({}, ...))``.

    Built from empty :class:`Component` instances so the expected output
    can be spelled out exactly without depending on the ``repr`` of any
    parsed property value.
    zVCALENDAR({}z, VEVENT({}r   r   N)r   Úranger   Úadd_componentr   )r   r   ÚparentÚ_ÚchildÚexpectedr   r   r	   Ú,test_repr_exact_output_for_nested_components.   s   	
r$   c                  C   s2   t ƒ } |  tƒ ¡ |  tƒ ¡ t| ƒdksJ ‚dS )zThe exact ``repr()`` string for sibling subcomponents matches the
    previous recursive format: ``VCALENDAR({}, VEVENT({}), VEVENT({}))``.
    z%VCALENDAR({}, VEVENT({}), VEVENT({}))N)r   r   r   r   )r   r   r   r	   Ú-test_repr_exact_output_for_sibling_componentsA   s   r%   )Ú__doc__ÚpytestÚ	icalendarr   r   Úintr   r
   ÚmarkÚparametrizer   r   r$   r%   r   r   r   r	   Ú<module>   s    

