icalendar.parser.ical.lazy module#

Special parsing for calendar components.

class icalendar.parser.ical.lazy.LazyCalendarIcalParser(data, component_factory, types_factory)[source]#

Bases: ComponentIcalParser

A parser for calendar components.

Instead of parsing the components, LazyComponents are created. Parsing can happen on demand.

A calendar may grow over time, with its subcomponents greatly increasing in number, and requiring more memory and time to fully parse. This optimization lazily parses calendar files without consuming more memory than necessary, reducing the initial time it takes to access meta data.

Initialize the parser with the raw data.

Parameters:
  • data (bytes | str | list[Contentline]) – The raw iCalendar data to parse, either as bytes or a list of content lines.

  • component_factory (ComponentFactory) – The factory to use for creating components.

  • types_factory (TypesFactory) – The factory to use for creating property values.

get_subcomponent_parser(content_lines)[source]#

Get the parser for a subcomponent.

Parameters:

content_lines (list[Contentline]) – The content lines of the subcomponent.

Return type:

ComponentIcalParser

handle_begin_component(vals)[source]#

Begin a new component.

This may be the first component.

handle_lazy_begin_component(component_name)[source]#

Begin a new component, but do not parse it yet.

Parameters:

component_name (str) – The upper case name of the component, for example, "VEVENT".

Return type:

None

parse_instantly: ClassVar[tuple[str, ...]] = ('VCALENDAR',)#

Parse these components immediately, instead of lazily.

All other components are parsed lazily.

prepare_components()[source]#

Prepare the lazily parsed components.

class icalendar.parser.ical.lazy.LazySubcomponent(name, parser)[source]#

Bases: object

A subcomponent that is evaluated lazily.

This class holds the raw data of the subcomponent ready for parsing.

Initialize the lazy subcomponent with the raw data.

is_lazy()[source]#

Return whether the subcomponents were accessed and parsed lazily.

Call parse() to get the fully parsed component.

Return type:

bool

is_parsed()[source]#

Return whether the subcomponent is already parsed.

Return type:

bool

property name: str#

The name of the subcomponent.

The name is uppercased, per RFC 5545 Section 2.1.

parse()[source]#

Parse the raw data and return the component.

Return type:

Component

walk(name)[source]#

Walk through this component.

This only parses the component if necessary.

Parameters:

name (str) – The name to match for all components in the calendar, then walk through and parse the resulting matches.

Return type:

list[Component]

with_uid(uid)[source]#

Return the components containing the given uid.

This only parses the component if necessary.

Parameters:

uid (str) – The UID of the components.

Return type:

list[Component]