1 from ...types import serializable
4 class Comment(str, serializable.Type):
6 A revision comment. This class behaves identically to
7 :class:`str` except that it takes and stores an additional parameter
8 recording whether the comment was deleted or not.
10 >>> from mw.xml_dump import Comment
12 >>> c = Comment("foo")
19 Was the comment deleted? | `bool`
23 def __new__(cls, string_or_comment="", deleted=False):
24 if isinstance(string_or_comment, cls):
25 return string_or_comment
27 inst = super().__new__(cls, string_or_comment)
28 inst.initialize(string_or_comment, deleted)
31 def initialize(self, string, deleted):
32 self.deleted = bool(deleted)
35 return str.__str__(self)
38 return "{0}({1})".format(
39 self.__class__.__name__,
42 "deleted={0}".format(repr(self.deleted))
48 "string_or_comment": str(self),
49 "deleted": self.deleted
53 def from_element(cls, e):
54 return cls(e.text, e.attr('deleted', False))