o
    ÌÄ.j  ã                   @  sZ   d Z ddlmZ ddlZddlmZ ddlmZ er ddlm	Z	 G dd„ deƒZ
dgZdS )	zA factory to create components.é    )ÚannotationsN)ÚTYPE_CHECKING)ÚCaselessDict©Ú	Componentc                      s4   e Zd ZdZ‡ fdd„Zddd	„Zddd„Z‡  ZS )ÚComponentFactoryaª  Registered components from :rfc:`7953` and :rfc:`5545`.

    To get a component, use this class as shown below.

    .. code-block:: pycon

        >>> from icalendar import ComponentFactory
        >>> factory = ComponentFactory()
        >>> event_class = factory.get_component_class('VEVENT')
        >>> event_class()
        VEVENT({})

    Automatically creates custom component classes for unknown names (X-components,
    IANA-components). Custom components are never dropped per :rfc:`5545`.

    .. code-block:: pycon

        >>> factory = ComponentFactory()
        >>> custom_class = factory.get_component_class('X-VENDOR')
        >>> custom_class()
        X-VENDOR({})

    If a component class is not yet supported, it can be either created
    using :meth:`get_component_class` or added manually as a subclass of
    :class:`~icalendar.cal.component.Component`.
    See :doc:`/how-to/custom-components` for details.
    c                   sø   t ƒ j|i |¤Ž ddlm} ddlm} ddlm} ddlm	} ddl
m} ddlm} ddlm}	 dd	lm}
m}m} dd
lm} |  |¡ |  |¡ |  |¡ |  |	¡ |  |¡ |  |
¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |¡ dS )z#Set keys to upper for initial dict.r   )ÚAlarm)ÚAvailability)Ú	Available)ÚCalendar)ÚEvent)ÚFreeBusy)ÚJournal)ÚTimezoneÚTimezoneDaylightÚTimezoneStandard)ÚTodoN)ÚsuperÚ__init__Úicalendar.cal.alarmr   Úicalendar.cal.availabilityr	   Úicalendar.cal.availabler
   Úicalendar.cal.calendarr   Úicalendar.cal.eventr   Úicalendar.cal.free_busyr   Úicalendar.cal.journalr   Úicalendar.cal.timezoner   r   r   Úicalendar.cal.todor   Úadd_component_class)ÚselfÚargsÚkwargsr   r	   r
   r   r   r   r   r   r   r   r   ©Ú	__class__© úT/home/thesage/.local/lib/python3.10/site-packages/icalendar/cal/component_factory.pyr   +   s*   









zComponentFactory.__init__Úclsútype[Component]ÚreturnÚNonec                 C  s   || |j < dS )zpAdd a component class to the factory.

        Parameters:
            cls: The component class to add.
        N)Úname)r   r&   r$   r$   r%   r   H   s   z$ComponentFactory.add_component_classr*   Ústrc                 C  sL   |   |¡}|du r$ddlm} tt dd|¡|fd| ¡ iƒ}|  |¡ |S )a  Get the component class from the factory.

        This also creates and adds the component class if it does not exist.

        Parameters:
            name: The name of the component, for example, ``"VCALENDAR"``.

        Returns:
            The registered component class.
        Nr   r   z[^\w]+Ú r*   )ÚgetÚicalendar.cal.componentr   ÚtypeÚreÚsubÚupperr   )r   r*   Úcomponent_classr   r$   r$   r%   Úget_component_classP   s   
ÿ
z$ComponentFactory.get_component_class)r&   r'   r(   r)   )r*   r+   r(   r'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   Ú__classcell__r$   r$   r"   r%   r      s
    
r   )r8   Ú
__future__r   r0   Útypingr   Úicalendar.caselessdictr   Ú	icalendarr   r   Ú__all__r$   r$   r$   r%   Ú<module>   s    
X