icalendar.parser_tools module#

Tools for parsing.

icalendar.parser_tools.DEFAULT_ENCODING = 'utf-8'#

The default encoding to use when encoding or decoding iCalendar data.

icalendar.parser_tools.ICAL_TYPE = str | bytes#

The type of data that can be encoded or decoded.

icalendar.parser_tools.SEQUENCE_TYPES = (<class 'list'>, <class 'tuple'>)#

The supported sequence types.

icalendar.parser_tools.data_encode(data, encoding='utf-8')[source]#

Encode all data structures to the given encoding.

Currently Unicode strings, dicts, and lists are supported.

Parameters:
  • data (str | bytes | dict | list) – Required. The data structure to encode.

  • encoding (str) – The encoding to use in the conversion. Default is DEFAULT_ENCODING, set in parser_tools.

Return type:

bytes | list[bytes] | dict

Returns:

The encoded data structure.

icalendar.parser_tools.from_unicode(value, encoding='utf-8')[source]#

Converts a value to bytes, even if it is already bytes.

Parameters:
  • value (str | bytes) – The value to convert.

  • encoding (str) – The encoding to use in the conversion.

Return type:

bytes

Returns:

The bytes representation of the value.

icalendar.parser_tools.to_unicode(value, encoding='utf-8-sig')[source]#

Converts a value to Unicode, even if it is already a Unicode string.

Parameters:
  • value (str | bytes) – The value to convert.

  • encoding (str) – The encoding to use in the conversion.

Return type:

str

Returns:

The Unicode string representation of the value.