icalendar.parser.string module#
Functions for manipulating strings and bytes.
- icalendar.parser.string.escape_char(text)[source]#
Format value according to iCalendar TEXT escaping rules.
Deprecated since version 7.0.0: Use the private
_escape_char()internally. For external use, this function is deprecated. Please use alternative escaping methods or contact the maintainers.Escapes special characters in text values according to RFC 5545 Section 3.3.11 rules. The order of replacements matters to avoid double-escaping.
- Parameters:
- Return type:
- Returns:
The escaped text with special characters escaped.
Note
The replacement order is critical:
\N->\n(normalize newlines to lowercase)\->\\(escape backslashes);->\;(escape semicolons),->\,(escape commas)\r\n->\n(normalize line endings)"\n"->r"\n"(transform a newline character to a literal, or raw, newline character)
- icalendar.parser.string.escape_string(val)[source]#
Escape backslash sequences to URL-encoded hex values.
Converts backslash-escaped characters to their percent-encoded hex equivalents. This is used for parameter parsing to preserve escaped characters during processing.
- Parameters:
val (
str) – The string with backslash escapes.- Return type:
- Returns:
The string with backslash escapes converted to percent encoding.
Note
Conversions:
\,->%2C\:->%3A\;->%3B\\->%5C
- icalendar.parser.string.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).
- Return type:
- icalendar.parser.string.unescape_char(text)[source]#
Unescape iCalendar TEXT values.
Deprecated since version 7.0.0: Use the private
_unescape_char()internally. For external use, this function is deprecated. Please use alternative unescaping methods or contact the maintainers.Reverses the escaping applied by
escape_char()according to RFC 5545 Section 3.3.11 TEXT escaping rules.- Parameters:
- Return type:
- Returns:
The unescaped text, or
Noneiftextis neitherstrnorbytes.
Note
The replacement order is critical to avoid double-unescaping:
\N->\n(intermediate step)\r\n->\n(normalize line endings)\n-> newline (unescape newlines)\,->,(unescape commas)\;->;(unescape semicolons)\\->\(unescape backslashes last)
- icalendar.parser.string.unescape_string(val)[source]#
Unescape URL-encoded hex values to their original characters.
Reverses
escape_string()by converting percent-encoded hex values back to their original characters. This is used for parameter parsing.- Parameters:
val (
str) – The string with percent-encoded values.- Return type:
- Returns:
The string with percent encoding converted to characters.
Note
Conversions:
%2C->,%3A->:%3B->;%5C->\
- icalendar.parser.string.validate_token(name)[source]#
Validate that a name is a valid iCalendar token.
Checks if the name matches the RFC 5545 token syntax using the NAME regex pattern (
[\w.-]+).- Parameters:
name (
str) – The token name to validate.- Raises:
ValueError – If the name is not a valid token.
- Return type: