icalendar.cal.component_factory module#
A factory to create components.
- class icalendar.cal.component_factory.ComponentFactory(*args, **kwargs)[source]#
Bases:
CaselessDictRegistered components from RFC 7953 and RFC 5545.
To get a component, use this class as shown below.
>>> 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.
>>> 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
get_component_class()or added manually as a subclass ofComponent. See Custom components for details.Set keys to upper for initial dict.
- get_component_class(name)[source]#
Get the component class from the factory.
This also creates and adds the component class if it does not exist.
- Parameters:
name (
str) – The name of the component, for example,"VCALENDAR".- Return type:
- Returns:
The registered component class.
- Raises:
InvalidToken – If the name is not a valid iCalendar token.