icalendar.parser.content_line module#

parsing and generation of content lines

class icalendar.parser.content_line.Contentline(value, strict=False, encoding='utf-8')[source]#

Bases: str

A content line is a string that can be folded and parsed into parts.

Raises:

ValueError – If the value contains \n.

classmethod from_ical(ical, strict=False)[source]#

Unfold the content lines in an iCalendar into long content lines.

classmethod from_parts(name, params, values, sorted=True)[source]#

Turn a parts into a content line.

Raises:

TypeError – If params is not type Parameters.

parts()[source]#

Split the line into name, parameters, and unescaped values parts.

Properly handles escaping with backslashes and double-quote sections to avoid corrupting URL-encoded characters in values.

The backslash sequences in the values are unescaped, as for the values of TEXT properties, while URL encoding is preserved. Use raw_parts() to get the values verbatim instead.

Examples

With parameter:

DESCRIPTION;ALTREP="cid:part1.0001@example.org":The Fall'98 Wild

Without parameters:

DESCRIPTION:The Fall'98 Wild
Return type:

tuple[str, Parameters, str]

raw_parts()[source]#

Split the line into name, parameters, and raw values parts.

This is parts() without the unescaping: the values are returned verbatim, preserving both backslash sequences and URL encoding. It is used for RFC 7265 UNKNOWN values, whose real value type—and therefore whose escaping rules—are not known.

See parts() for the parts themselves and for examples.

Return type:

tuple[str, Parameters, str]

strict#
to_ical()[source]#

Long content lines are folded so they are less than 75 characters wide.

value_separator_index()[source]#

Return the index of the colon that separates the value.

This is the first colon that is not inside a quoted parameter section.

A colon inside a quoted parameter value is skipped, for example, ALTREP="http://x". A colon that belongs to the value is not mistaken for the colon separator, since TEXT doesn't escape :.

An escaped double quote (\") inside a quoted section doesn't close it. RFC 2445 Section 4.3.11-compliant input, such as CN="Qu\"ote", both keeps its quote state and the separator after it is still found.

A DQUOTE preceded by a literal backslash closes the section when the separator or the end of the line follows it. This is the shape icalendar itself writes for values ending in a backslash.

Return type:

int

Returns:

An integer representing the index position of the separator, or -1 if there is none.

class icalendar.parser.content_line.Contentlines(iterable=(), /)[source]#

Bases: list[Contentline]

I assume that iCalendar files generally are a few kilobytes in size. Then this should be efficient. for Huge files, an iterator should probably be used instead.

classmethod from_ical(st)[source]#

Parses a string into content lines.

to_ical()[source]#

Simply join self.