icalendar.prop.text module#

TEXT values from RFC 5545.

class icalendar.prop.text.vText(value, encoding='utf-8', /, params=None)[source]#

Bases: str

vText is a data type that contains human-readable text values.

The vText property uses the RFC 5545 Section 3.3.11 TEXT value type in various icalendar properties to show free-form text that others can read. This class can be created from Python strings, and can be used to add text descriptions to calendar events.

To create a TEXT object, pass in the string you want when creating the object.

To add a line break, use \n or \N.

Use the LANGUAGE property parameter to set the language of the text.

When the TEXT object is created, CONTROL characters other than HTAB are removed so both to_ical() and to_jcal() stay valid RFC 5545 Section 3.3.11 TEXT. Parsing does not raise; the value is corrected. When the TEXT object is serialized to an icalendar stream, COMMA, SEMICOLON, BACKSLASH, and line breaks are escaped.

Contrast TEXT with the UNKNOWN value data type specified in RFC 7265 Section 5. UNKNOWN is implemented in the Python class vUnknown, which does not apply this escaping and preserves its value verbatim, because the escaping rules of an unrecognized value type are not known. vUnknown deliberately does not inherit from vText, so the two don't share escaping behavior.

Changed in version 0.0.0: Remove CONTROL characters other than HTAB.

Examples

vText property as a TEXT value type.

Project XYZ Final Review\nConference Room - 3B\nCome Prepared.

Create a vText property, and display it in a readable format.

>>> from icalendar.prop import vText
>>> desc = 'Project XYZ Final Review\nConference Room - 3B\nCome Prepared.'
>>> text = vText(desc)
>>> text
vText(b'Project XYZ Final Review\\nConference Room - 3B\\nCome Prepared.')
>>> print(text.ical_value)
Project XYZ Final Review
Conference Room - 3B
Come Prepared.

Add a SUMMARY to an event, then display its value as a vText property then in a readable format:

>>> from icalendar import Event
>>> event = Event()
>>> event.add('SUMMARY', desc)
>>> event['SUMMARY']
vText(b'Project XYZ Final Review\\nConference Room - 3B\\nCome Prepared.')
>>> print(event.to_ical().decode())
BEGIN:VEVENT
SUMMARY:Project XYZ Final Review\nConference Room - 3B\nCome Prepared.
END:VEVENT
property ALTREP: str | None#

ALTREP - Specify an alternate text representation for the property value.

Description:

This parameter specifies a URI that points to an alternate representation for a textual property value. A property specifying this parameter MUST also include a value that reflects the default representation of the text value. The URI parameter value MUST be specified in a quoted-string.

Note

While there is no restriction imposed on the URI schemes allowed for this parameter, Content Identifier (CID) RFC 2392, HTTP RFC 2616, and HTTPS RFC 2818 are the URI schemes most commonly used by current implementations.

property LANGUAGE: str | None#

Specify the language for text values in a property or property parameter.

Description:

This parameter identifies the language of the text in the property value and of all property parameter values of the property. The value of the "LANGUAGE" property parameter is that defined in RFC 5646.

For transport in a MIME entity, the Content-Language header field can be used to set the default language for the entire body part. Otherwise, no default language is assumed.

property RELTYPE: RELTYPE#

Specify the type of hierarchical relationship associated with a component.

Conformance:

RFC 5545 introduces the RELTYPE property parameter. RFC 9253 adds new values.

Description:

This parameter can be specified on a property that references another related calendar. The parameter specifies the hierarchical relationship type of the calendar component referenced by the property. The parameter value can be PARENT, to indicate that the referenced calendar component is a superior of calendar component; CHILD to indicate that the referenced calendar component is a subordinate of the calendar component; or SIBLING to indicate that the referenced calendar component is a peer of the calendar component. If this parameter is not specified on an allowable property, the default relationship type is PARENT. Applications MUST treat x-name and iana-token values they don't recognize the same way as they would the PARENT value.

Setter accepts:

str | None

default_value: ClassVar[str] = 'TEXT'#
encoding#
classmethod examples()[source]#

Examples of vText.

Return type:

list[Self]

classmethod from_ical(ical)[source]#

Parse a TEXT value from its iCalendar representation.

Control characters that RFC 5545 Section 3.3.11 does not allow in TEXT get removed.

Changed in version 0.0.0: Don't raise for unsafe characters in TEXT, but instead remove them. The parsed object can now be read and later serialized.

See also

Return type:

Self

classmethod from_jcal(jcal_property)[source]#

Parse jCal from RFC 7265.

Parameters:

jcal_property (list) – The jCal property to parse.

Raises:

JCalParsingError – If the provided jCal is invalid.

Return type:

Self

classmethod from_xcal(xml)[source]#

Parse xCal according to RFC 6321.

Parameters:
  • parser – Required. The xCal to parse or a parser.

  • params – Required. The parameters of the xCal element.

Raises:

XCalParsingError – If the provided xCal is invalid.

Return type:

VProp

classmethod from_xcal_in_recur(xml)[source]#

Parse xCal according to RFC 6321.

Parameters:
  • parser – Required. The xCal to parse or a parser.

  • _params – Required. The parameters of the xCal element.

Raises:

XCalParsingError – If the provided xCal is invalid.

Return type:

VProp

property ical_value: str#

The string value of the text.

params: Parameters#
classmethod parse_jcal_value(jcal_value)[source]#

Parse a jCal value into a vText.

Return type:

Self

to_ical()[source]#

Serialize this TEXT value with RFC 5545 escaping.

Return type:

bytes

to_jcal(name)[source]#

The jCal representation of this property according to RFC 7265.

Return type:

list

to_xcal(element)[source]#

Add the xCal representation of this property according to RFC 6321.

Return type:

None