o
    .jq                     @  s   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ erXddlmZ ddlmZ G dd deZdgZdS )zSelecting components by name.    )annotationsN)defaultdict)TYPE_CHECKINGSequence)EventAdapter)JournalAdapter)TodoAdapter)
Occurrence)Alarms)SelectComponents)Series)cached_property)	Component)ComponentAdapterc                   @  sR   e Zd ZU dZeeee gZde	d< e
dddZdeefdddZdddZdS )ComponentsWithNamea  This is a component collecttion strategy.

    Components can be collected in different ways.
    This class allows extension of the functionality by
    - subclassing to filter the resulting components
    - composition to combine collection behavior (see AllKnownComponents)
    z/list[type[ComponentAdapter] | SelectComponents]component_adaptersreturn dict[str:type[ComponentAdapter]]c                 C  s   dd | j D S )z A mapping of component adapters.c                 S  s   i | ]}|  |qS  )component_name).0adapterr   r   Y/home/thesage/.local/lib/python3.10/site-packages/recurring_ical_events/selection/name.py
<dictcomp>+   s    
z:ComponentsWithName._component_adapters.<locals>.<dictcomp>)r   )selfr   r   r   _component_adapters(   s   z&ComponentsWithName._component_adaptersNnamestrr   type[ComponentAdapter] | Noneseriestype[Series]
occurrencetype[Occurrence]Nonec                   sp   |du r|| j vrtd| dd| j  d| j | }|tur-| G  fddd|}|| _|| _|| _dS )ad  Create a new way of collecting components.

        name - the name of the component to collect ("VEVENT", "VTODO", "VJOURNAL")
        adapter - the adapter to use for these components with that name
        series - the series class that hold a series of components
        occurrence - the occurrence class that creates the resulting components
        N"zC" is an unknown name for a recurring component. I only know these: z, .c                      s   e Zd Z ZdS )z+ComponentsWithName.__init__.<locals>.seriesN)__name__
__module____qualname__r!   r   _occurrencer   r   r   H   s    r   )r   
ValueErrorjoinr	   _name_series_adapter)r   r   r   r   r!   r   r)   r   __init__/   s   



zComponentsWithName.__init__sourcer   suppress_errorstuple[Exception]Sequence[Series]c              	   C  s   t | jtr| j||S tt}|| jD ]}| |}||j 	| qg }|
 D ]}t| |	| | W d   n1 sGw   Y  q-|S )zCollect all components from the source component.

        suppress_errors - a list of errors that should be suppressed.
            A Series of events with such an error is removed from all results.
        N)
isinstancer/   r   collect_series_fromr   listwalkr-   uidappendvalues
contextlibsuppressr.   )r   r1   r2   
components	componentr   resultr   r   r   r6   O   s   
z&ComponentsWithName.collect_series_from)r   r   )
r   r   r   r   r   r    r!   r"   r   r#   )r1   r   r2   r3   r   r4   )r&   r'   r(   __doc__r   r   r   r
   r   __annotations__r   r   r   r	   r0   r6   r   r   r   r   r      s   
 		 r   )rA   
__future__r   r<   collectionsr   typingr   r   $recurring_ical_events.adapters.eventr   &recurring_ical_events.adapters.journalr   #recurring_ical_events.adapters.todor    recurring_ical_events.occurrencer	   %recurring_ical_events.selection.alarmr
   $recurring_ical_events.selection.baser   recurring_ical_events.seriesr   recurring_ical_events.utilr   icalendar.calr   (recurring_ical_events.adapters.componentr   r   __all__r   r   r   r   <module>   s$    
L