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

Revision 136, 2.3 KB checked in by xi, 9 years ago (diff)

Major refactoring.

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, encoding=None):
37        self.start_mark = start_mark
38        self.end_mark = end_mark
39        self.encoding = encoding
40
41class StreamEndEvent(Event):
42    pass
43
44class DocumentStartEvent(Event):
45    def __init__(self, start_mark=None, end_mark=None,
46            explicit=None, version=None, tags=None):
47        self.start_mark = start_mark
48        self.end_mark = end_mark
49        self.explicit = explicit
50        self.version = version
51        self.tags = tags
52
53class DocumentEndEvent(Event):
54    def __init__(self, start_mark=None, end_mark=None,
55            explicit=None):
56        self.start_mark = start_mark
57        self.end_mark = end_mark
58        self.explicit = explicit
59
60class AliasEvent(NodeEvent):
61    pass
62
63class ScalarEvent(NodeEvent):
64    def __init__(self, anchor, tag, implicit, value,
65            start_mark=None, end_mark=None, style=None):
66        self.anchor = anchor
67        self.tag = tag
68        self.implicit = implicit
69        self.value = value
70        self.start_mark = start_mark
71        self.end_mark = end_mark
72        self.style = style
73
74class SequenceStartEvent(CollectionStartEvent):
75    pass
76
77class SequenceEndEvent(CollectionEndEvent):
78    pass
79
80class MappingStartEvent(CollectionStartEvent):
81    pass
82
83class MappingEndEvent(CollectionEndEvent):
84    pass
85
Note: See TracBrowser for help on using the repository browser.