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 self = super().__new__(cls, value)
26 self.params = Parameters(params)
27 return self
28
29 def to_ical(self) -> bytes:
30 return self.encode(DEFAULT_ENCODING)
31
32 @classmethod
33 def from_ical(cls, ical: ICAL_TYPE) -> Self:
34 return cls(ical)
35
36
37__all__ = ["vInline"]