Debian Codegraph @

strictyaml/ruamel/events.py

raw
1 # coding: utf-8
2
3 # Abstract classes.
4
5 if False: # MYPY
6 from typing import Any, Dict, Optional, List # NOQA
7
8
9 def CommentCheck():
10 # type: () -> None
11 pass
12
13
14 class Event(object):
15 __slots__ = "start_mark", "end_mark", "comment"
16
17 def __init__(self, start_mark=None, end_mark=None, comment=CommentCheck):
18 # type: (Any, Any, Any) -> None
19 self.start_mark = start_mark
20 self.end_mark = end_mark
21 # assert comment is not CommentCheck
22 if comment is CommentCheck:
23 comment = None
24 self.comment = comment
25
26 def __repr__(self):
27 # type: () -> Any
28 attributes = [
29 key
30 for key in ["anchor", "tag", "implicit", "value", "flow_style", "style"]
31 if hasattr(self, key)
32 ]
33 arguments = ", ".join(
34 ["%s=%r" % (key, getattr(self, key)) for key in attributes]
35 )
36 if self.comment not in [None, CommentCheck]:
37 arguments += ", comment={!r}".format(self.comment)
38 return "%s(%s)" % (self.__class__.__name__, arguments)
39
40
41 class NodeEvent(Event):
42 __slots__ = ("anchor",)
43
44 def __init__(self, anchor, start_mark=None, end_mark=None, comment=None):
45 # type: (Any, Any, Any, Any) -> None
46 Event.__init__(self, start_mark, end_mark, comment)
47 self.anchor = anchor
48
49
50 class CollectionStartEvent(NodeEvent):
51 __slots__ = "tag", "implicit", "flow_style", "nr_items"
52
53 def __init__(
54 self,
55 anchor,
56 tag,
57 implicit,
58 start_mark=None,
59 end_mark=None,
60 flow_style=None,
61 comment=None,
62 nr_items=None,
63 ):
64 # type: (Any, Any, Any, Any, Any, Any, Any, Optional[int]) -> None
65 NodeEvent.__init__(self, anchor, start_mark, end_mark, comment)
66 self.tag = tag
67 self.implicit = implicit
68 self.flow_style = flow_style
69 self.nr_items = nr_items
70
71
72 class CollectionEndEvent(Event):
73 __slots__ = ()
74
75
76 # Implementations.
77
78
79 class StreamStartEvent(Event):
80 __slots__ = ("encoding",)
81
82 def __init__(self, start_mark=None, end_mark=None, encoding=None, comment=None):
83 # type: (Any, Any, Any, Any) -> None
84 Event.__init__(self, start_mark, end_mark, comment)
85 self.encoding = encoding
86
87
88 class StreamEndEvent(Event):
89 __slots__ = ()
90
91
92 class DocumentStartEvent(Event):
93 __slots__ = "explicit", "version", "tags"
94
95 def __init__(
96 self,
97 start_mark=None,
98 end_mark=None,
99 explicit=None,
100 version=None,
101 tags=None,
102 comment=None,
103 ):
104 # type: (Any, Any, Any, Any, Any, Any) -> None
105 Event.__init__(self, start_mark, end_mark, comment)
106 self.explicit = explicit
107 self.version = version
108 self.tags = tags
109
110
111 class DocumentEndEvent(Event):
112 __slots__ = ("explicit",)
113
114 def __init__(self, start_mark=None, end_mark=None, explicit=None, comment=None):
115 # type: (Any, Any, Any, Any) -> None
116 Event.__init__(self, start_mark, end_mark, comment)
117 self.explicit = explicit
118
119
120 class AliasEvent(NodeEvent):
121 __slots__ = ()
122
123
124 class ScalarEvent(NodeEvent):
125 __slots__ = "tag", "implicit", "value", "style"
126
127 def __init__(
128 self,
129 anchor,
130 tag,
131 implicit,
132 value,
133 start_mark=None,
134 end_mark=None,
135 style=None,
136 comment=None,
137 ):
138 # type: (Any, Any, Any, Any, Any, Any, Any, Any) -> None
139 NodeEvent.__init__(self, anchor, start_mark, end_mark, comment)
140 self.tag = tag
141 self.implicit = implicit
142 self.value = value
143 self.style = style
144
145
146 class SequenceStartEvent(CollectionStartEvent):
147 __slots__ = ()
148
149
150 class SequenceEndEvent(CollectionEndEvent):
151 __slots__ = ()
152
153
154 class MappingStartEvent(CollectionStartEvent):
155 __slots__ = ()
156
157
158 class MappingEndEvent(CollectionEndEvent):
159 __slots__ = ()