
    i                         d Z ddlmZ ddlmZmZmZ ddlmZ erddl	m
Z
 ddlmZ ddlmZ  G d d	          Z G d
 d          Zd	dgZdS )ztPagination for recurring ical events.

See https://github.com/niccokunzmann/python-recurring-ical-events/issues/211
    )annotations)TYPE_CHECKINGIteratorOptional)compare_greater)	Component)
Occurrence)Timec                  l    e Zd ZdZdddZedd	            ZddZedd            ZddZ	ddZ
ddZdS )Pagead  One page in a series of pages.

    Examples:
        Check if the page has components.

        .. code-block:: python

            if page:
                print(f"We have {len(page)} components.")
        
        Go though the components:
        
        .. code-block:: python

            for component in page:
                print(component)
     
componentslist[Component]next_page_idstrc                "    || _         || _        dS )z "Create a new page.N)_components_next_page_id)selfr   r   s      V/root/projects/butler/venv/lib/python3.11/site-packages/recurring_ical_events/pages.py__init__zPage.__init__&   s    %)    returnc                    | j         S )z All the components of this page.)r   r   s    r   r   zPage.components+   s     r   boolc                    | j         dk    S )z*Wether there is a page following this one.r   r   r   s    r   has_next_pagezPage.has_next_page0   s     B&&r   c                    | j         S )z"The id of the next page or ``''``.r   r   s    r   r   zPage.next_page_id4   s     !!r   intc                *    t          | j                  S )zThe number of components.)lenr   r   s    r   __len__zPage.__len__9   s    4?###r   c                    | j         dk    S )zBWether this is the last page and there is no other page following.r   r!   r   s    r   is_lastzPage.is_last=   s    !R''r   Iterator[Component]c                *    t          | j                  S )z'Return an iterator over the components.)iterr   r   s    r   __iter__zPage.__iter__A   s    DO$$$r   N)r   )r   r   r   r   )r   r   )r   r   )r   r   r   r"   )r   r(   )__name__
__module____qualname____doc__r   propertyr   r   r   r%   r'   r+    r   r   r   r      s         $* * * * *
       X ' ' ' ' " " " X"$ $ $ $( ( ( (% % % % % %r   r   c                  X    e Zd ZdZ	 	 dddZedd            ZddZddZddZ	ddZ
dS )Pagesz|A pagination configuration to iterate over pages.

    This is an :class:`Iterator` that returns :class:`Page` objects.
    NFoccurrence_iteratorIterator[Occurrence]sizer"   stopOptional[Time]keep_recurrence_attributesr   c                    || _         || _        || _        | j        dk    rt          d| j         d          || _        d| _        | j         D ],}| j        t          | j        |j                  r|| _         dS dS )z0Create a new paginated iterator over components.r   z-A page must have at least one component, not .N)	_iterator_stop_size
ValueError_keep_recurrence_attributes_next_occurrencer   start)r   r5   r7   r8   r:   
occurrences         r   r   zPages.__init__L   s     -

:??M
MMM   ,F(6:. 	 	Jz!_TZAQ%R%R!(2%EE	 	r   r   c                    | j         S )z*The maximum number of components per page.)r?   r   s    r   r7   z
Pages.sizeb   s     zr   r   c                0    | D ]}|c S t          g           S )zGenerate the next page.

        In contrast to ``next(pages)``, this does not raise :class:`StopIteration`.
        But it works the same: the next page is generated and returned.
        The last page is empty.
        )r   )r   pages     r   generate_next_pagezPages.generate_next_pageg   s'      	 	DKKKBxxr   c                L   | j         t          | j         }|g}| j        D ]U}| j        t	          |j        | j                  r n1|}t          |          | j        k     r|                    |           U |d         |k    rd| _         n|| _         | 	                    |          S )zReturn the next page.N)
rB   StopIterationr=   r>   r   rC   r$   r?   append_create_page_from_occurrences)r   last_occurrenceoccurrencesrD   s       r   __next__zPages.__next__r   s     (/&'. 	 	Jz%/*:JDJ*W*W%(O;$*,,"":....r?o--$(D!!$3D!11+>>>r   rO   list[Occurrence]c                     t           fd|D              j         j        j                                        nd          S )z.Create a new page from the occurrences listed.c                D    g | ]}|                     j                  S r2   )as_componentrA   ).0rD   r   s     r   
<listcomp>z7Pages._create_page_from_occurrences.<locals>.<listcomp>   s:        ''(HII  r   Nr   r   )r   rB   id	to_string)r   rO   s   ` r   rM   z#Pages._create_page_from_occurrences   sh       "-  
 $0 .1;;===
 
 
 	
r   c                    | S )zReturn the iterator.r2   r   s    r   r+   zPages.__iter__   s    r   )NF)r5   r6   r7   r"   r8   r9   r:   r   r,   )r   r   )rO   rQ   r   r   )r   r4   )r-   r.   r/   r0   r   r1   r7   rH   rP   rM   r+   r2   r   r   r4   r4   F   s           $+0    ,    X	 	 	 	? ? ? ?(

 

 

 

     r   r4   N)r0   
__future__r   typingr   r   r   recurring_ical_events.utilr   	icalendarr    recurring_ical_events.occurrencer	   recurring_ical_events.typesr
   r   r4   __all__r2   r   r   <module>ra      s    
 # " " " " " 4 4 4 4 4 4 4 4 4 4 6 6 6 6 6 6 1######;;;;;;0000000% 0% 0% 0% 0% 0% 0% 0%fN N N N N N N Nb 7
r   