o
    .j                     @  s   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	 d	ZG d
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                   @  s`   e Zd ZdZddddZedd
dZdddZedddZdddZ	dddZ
d ddZdS )!PageaT  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                 C  s   || _ || _dS )z "Create a new page.N)_components_next_page_id)selfr   r    r   P/home/thesage/.local/lib/python3.10/site-packages/recurring_ical_events/pages.py__init__&   s   
zPage.__init__returnc                 C     | j S )z All the components of this page.)r   r   r   r   r   r   +      zPage.componentsboolc                 C  s
   | j dkS )z*Wether there is a page following this one.r   r   r   r   r   r   has_next_page0      
zPage.has_next_pagec                 C  r   )z"The id of the next page or ``''``.r   r   r   r   r   r   4   r   zPage.next_page_idintc                 C  
   t | jS )zThe number of components.)lenr   r   r   r   r   __len__9   r   zPage.__len__c                 C  s
   | j dkS )zBWether this is the last page and there is no other page following.r   r   r   r   r   r   is_last=   r   zPage.is_lastIterator[Component]c                 C  r    )z'Return an iterator over the components.)iterr   r   r   r   r   __iter__A   r   zPage.__iter__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   r
      s    


r
   c                   @  sV   e Zd ZdZ		ddddZedddZdddZdddZd ddZ	d!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                 C  sl   || _ || _|| _| jdkrtd| j d|| _d| _| j D ]}| jdu s.t| j|jr1|| _ 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   r.   r0   r1   r3   
occurrencer   r   r   r   L   s   

zPages.__init__r   c                 C  r   )z*The maximum number of components per page.)r7   r   r   r   r   r0   b   r   z
Pages.sizer
   c                 C  s   | D ]}|  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   pager   r   r   generate_next_pageg   s   zPages.generate_next_pagec                 C  s   | j du rt| j }|g}| jD ]}| jdur t|j| jr  n|}t|| jk r/|| q |d |kr:d| _ n|| _ | 	|S )zReturn the next page.N)
r:   StopIterationr5   r6   r   r;   r!   r7   append_create_page_from_occurrences)r   last_occurrenceoccurrencesr<   r   r   r   __next__r   s   


zPages.__next__rD   list[Occurrence]c                   s4   t  fdd|D  jdur jj dS ddS )z.Create a new page from the occurrences listed.c                   s   g | ]}|  jqS r   )as_componentr9   ).0r<   r   r   r   
<listcomp>   s    
z7Pages._create_page_from_occurrences.<locals>.<listcomp>Nr   r   )r
   r:   id	to_string)r   rD   r   r   r   rB      s   


z#Pages._create_page_from_occurrencesc                 C  s   | S )zReturn the iterator.r   r   r   r   r   r&      s   zPages.__iter__)NF)r.   r/   r0   r   r1   r2   r3   r   r'   )r   r
   )rD   rF   r   r
   )r   r-   )r(   r)   r*   r+   r   r,   r0   r>   rE   rB   r&   r   r   r   r   r-   F   s    	


r-   N)r+   
__future__r   typingr   r   r   recurring_ical_events.utilr   	icalendarr    recurring_ical_events.occurrencer   recurring_ical_events.typesr	   r
   r-   __all__r   r   r   r   <module>   s    3Q