1from typing import Any
2
3from icalendar.compatibility import Self
4from icalendar.parser import Parameters
5from icalendar.parser_tools import DEFAULT_ENCODING, ICAL_TYPE, to_unicode
6
7
8class vInline(str):
9 """This is an especially dumb class that just holds raw unparsed text and
10 has parameters. Conversion of inline values are handled by the Component
11 class, so no further processing is needed.
12 """
13
14 params: Parameters
15 __slots__ = ("params",)
16
17 def __new__(
18 cls,
19 value: ICAL_TYPE,
20 encoding: str = DEFAULT_ENCODING,
21 /,
22 params: dict[str, Any] | None = None,
23 ) -> Self:
24 value = to_unicode(value, encoding=encoding)
25 if "\r" in value or "\n" in value:
26 raise ValueError(
27 f"An inline value may not contain CR or LF characters: {value!r}"
28 )
29 self = super().__new__(cls, value)
30 self.params = Parameters(params)
31 return self
32
33 def to_ical(self) -> bytes:
34 return self.encode(DEFAULT_ENCODING)
35
36 @classmethod
37 def from_ical(cls, ical: ICAL_TYPE) -> Self:
38 return cls(ical)
39
40
41__all__ = ["vInline"]