1 from ...types import serializable
2 from ...util import none_or
5 class Text(str, serializable.Type):
7 Revision text content. This class behaves identically to
8 :class:`str` except that it takes and stores an additional set of parameters.
11 Was the text deleted? : `bool`
13 What to do with extra whitespace? : `str`
15 TODO: ??? : `int` | `None`
17 TODO: ??? : `int` | `None`
19 >>> from mw.xml_dump import Text
30 def __new__(cls, string_or_text="", deleted=False, xml_space="preserve", id=None, bytes=None):
31 if isinstance(string_or_text, cls):
34 inst = super().__new__(cls, string_or_text)
35 inst.initialize(string_or_text, deleted, xml_space, id, bytes)
38 def initialize(self, string, deleted, xml_space, id, bytes):
39 self.deleted = bool(deleted)
40 self.xml_space = none_or(xml_space, str)
41 self.id = none_or(id, int)
42 self.bytes = none_or(bytes, int)
45 return str.__str__(self)
48 return "{0}({1})".format(
49 self.__class__.__name__,
52 "deleted={0}".format(repr(self.deleted))
58 "string_or_text": str(self),
59 "deleted": self.deleted,
60 "xml_space": self.xml_space,
66 def from_element(cls, e):
67 content = e.text or ""
70 deleted=e.attr('deleted', False),
71 xml_space=e.attr('xml:space'),