source: pyyaml/branches/working-on-emitter/lib/yaml/events.py @ 127

Revision 127, 2.1 KB checked in by xi, 9 years ago (diff)

Parser now provides style information. Allow empty plain scalars if a tag or anchor is given.

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