icalendar.parser module#

This module parses and generates contentlines as defined in RFC 5545 (iCalendar), but will probably work for other MIME types with similar syntax. Eg. RFC 2426 (vCard)

It is stupid in the sense that it treats the content purely as strings. No type conversion is attempted.

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

Bases: str

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

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

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

classmethod from_parts(name: str | bytes, params: Parameters, values, sorted: bool = True)[source]#

Turn a parts into a content line.

parts()[source]#

Split the content line up into (name, parameters, values) parts.

strict#
to_ical()[source]#

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

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

Bases: list

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.

class icalendar.parser.Parameters(*args, **kwargs)[source]#

Bases: CaselessDict

Parser and generator of Property parameter strings. It knows nothing of datatypes. Its main concern is textual structure.

always_quoted = ('ALTREP', 'DELEGATED-FROM', 'DELEGATED-TO', 'DIR', 'MEMBER', 'SENT-BY', 'X-ADDRESS', 'X-TITLE')#
classmethod from_ical(st, strict=False)[source]#

Parses the parameter format from ical text format.

params()[source]#

In RFC 5545 keys are called parameters, so this is to be consitent with the naming conventions.

quote_also = {'CN': " '"}#
to_ical(sorted: bool = True)[source]#
property value: VALUE | str | None#

The VALUE parameter from RFC 5545.

Description:

This parameter specifies the value type and format of the property value. The property values MUST be of a single value type. For example, a “RDATE” property cannot have a combination of DATE-TIME and TIME value types.

If the property’s value is the default value type, then this parameter need not be specified. However, if the property’s default value type is overridden by some other allowable value type, then this parameter MUST be specified.

Applications MUST preserve the value data for x-name and iana- token values that they don’t recognize without attempting to interpret or parse the value data.

icalendar.parser.dquote(val, always_quote=False)[source]#

Enclose parameter values containing [,;:] in double quotes.

icalendar.parser.escape_char(text)[source]#

Format value according to iCalendar TEXT escaping rules.

icalendar.parser.escape_string(val)[source]#
icalendar.parser.foldline(line, limit=75, fold_sep='\r\n ')[source]#

Make a string folded as defined in RFC5545 Lines of text SHOULD NOT be longer than 75 octets, excluding the line break. Long content lines SHOULD be split into a multiple line representations using a line “folding” technique. That is, a long line can be split between any two characters by inserting a CRLF immediately followed by a single linear white-space character (i.e., SPACE or HTAB).

icalendar.parser.param_value(value, always_quote=False)[source]#

Returns a parameter value.

icalendar.parser.q_join(lst, sep=',', always_quote=False)[source]#

Joins a list on sep, quoting strings with QUOTABLE chars.

icalendar.parser.q_split(st, sep=',', maxsplit=-1)[source]#

Splits a string on char, taking double (q)uotes into considderation.

icalendar.parser.rfc_6868_escape(param_value: str) str[source]#

Take care of RFC 6868 escaping.

  • ^ -> ^^

  • “ -> ^’

  • newline -> ^n

icalendar.parser.rfc_6868_unescape(param_value: str) str[source]#

Take care of RFC 6868 unescaping.

  • ^^ -> ^

  • ^n -> system specific newline

  • ^’ -> “

  • ^ with others stay intact

icalendar.parser.unescape_char(text)[source]#
icalendar.parser.unescape_list_or_string(val)[source]#
icalendar.parser.unescape_string(val)[source]#
icalendar.parser.validate_param_value(value, quoted=True)[source]#
icalendar.parser.validate_token(name)[source]#