source: pyyaml/trunk/lib/yaml/events.py @ 132

Revision 132, 2.5 KB checked in by xi, 8 years ago (diff)

Emitter is done!!!

Line 
1
2# Abstract classes.
3
4class Event:
5    def __init__(self, start_mark=None, end_mark=None):
6        self.start_mark = start_mark
7        self.end_mark = end_mark
8    def __repr__(self):
9        attributes = [key for key in ['anchor', 'tag', 'value']
10                if hasattr(self, key)]
11        arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
12                for key in attributes])
13        return '%s(%s)' % (self.__class__.__name__, arguments)
14
15class NodeEvent(Event):
16    def __init__(self, anchor, start_mark=None, end_mark=None):
17        self.anchor = anchor
18        self.start_mark = start_mark
19        self.end_mark = end_mark
20
21class CollectionStartEvent(NodeEvent):
22    def __init__(self, anchor, tag, start_mark=None, end_mark=None,
23            flow_style=None):
24        self.anchor = anchor
25        self.tag = tag
26        self.start_mark = start_mark
27        self.end_mark = end_mark
28        self.flow_style = flow_style
29
30class CollectionEndEvent(Event):
31    pass
32
33# Implementations.
34
35class StreamStartEvent(Event):
36    def __init__(self, start_mark=None, end_mark=None,
37            encoding=None, line_break=None, canonical=None,
38            indent=None, width=None):
39        self.start_mark = start_mark
40        self.end_mark = end_mark
41        self.encoding = encoding
42        self.line_break = line_break
43        self.canonical = canonical
44        self.indent = indent
45        self.width = width
46
47class StreamEndEvent(Event):
48    pass
49
50class DocumentStartEvent(Event):
51    def __init__(self, start_mark=None, end_mark=None,
52            explicit=None, version=None, tags=None):
53        self.start_mark = start_mark
54        self.end_mark = end_mark
55        self.explicit = explicit
56        self.version = version
57        self.tags = tags
58
59class DocumentEndEvent(Event):
60    def __init__(self, start_mark=None, end_mark=None,
61            explicit=None):
62        self.start_mark = start_mark
63        self.end_mark = end_mark
64        self.explicit = explicit
65
66class AliasEvent(NodeEvent):
67    pass
68
69class ScalarEvent(NodeEvent):
70    def __init__(self, anchor, tag, value, start_mark=None, end_mark=None,
71            implicit=None, style=None):
72        self.anchor = anchor
73        self.tag = tag
74        self.value = value
75        self.start_mark = start_mark
76        self.end_mark = end_mark
77        self.implicit = implicit
78        self.style = style
79
80class SequenceStartEvent(CollectionStartEvent):
81    pass
82
83class SequenceEndEvent(CollectionEndEvent):
84    pass
85
86class MappingStartEvent(CollectionStartEvent):
87    pass
88
89class MappingEndEvent(CollectionEndEvent):
90    pass
91
Note: See TracBrowser for help on using the repository browser.