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

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

Add style information to events generated by Parser.

RevLine 
[51]1
[130]2# Abstract classes.
3
[51]4class Event:
[130]5    def __init__(self, start_mark=None, end_mark=None):
[116]6        self.start_mark = start_mark
7        self.end_mark = end_mark
[51]8    def __repr__(self):
[130]9        attributes = [key for key in ['anchor', 'tag', 'value']
10                if hasattr(self, key)]
[51]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):
[130]16    def __init__(self, anchor, start_mark=None, end_mark=None):
[51]17        self.anchor = anchor
[116]18        self.start_mark = start_mark
19        self.end_mark = end_mark
[51]20
[130]21class CollectionStartEvent(NodeEvent):
22    def __init__(self, anchor, tag, start_mark=None, end_mark=None,
23            flow_style=None):
[51]24        self.anchor = anchor
25        self.tag = tag
[116]26        self.start_mark = start_mark
27        self.end_mark = end_mark
[130]28        self.flow_style = flow_style
[51]29
[130]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, canonical=None, indent=None, width=None):
[116]38        self.start_mark = start_mark
39        self.end_mark = end_mark
[130]40        self.encoding = encoding
41        self.canonical = canonical
42        self.indent = indent
43        self.width = width
[51]44
[130]45class StreamEndEvent(Event):
[51]46    pass
47
[130]48class DocumentStartEvent(Event):
49    def __init__(self, start_mark=None, end_mark=None,
50            implicit=None, version=None, tags=None):
51        self.start_mark = start_mark
52        self.end_mark = end_mark
53        self.implicit = implicit
54        self.version = version
55        self.tags = tags
[51]56
[130]57class DocumentEndEvent(Event):
58    def __init__(self, start_mark=None, end_mark=None,
59            implicit=None):
60        self.start_mark = start_mark
61        self.end_mark = end_mark
62        self.implicit = implicit
63
64class AliasEvent(NodeEvent):
[51]65    pass
66
[130]67class ScalarEvent(NodeEvent):
68    def __init__(self, anchor, tag, value, start_mark=None, end_mark=None,
69            implicit=None, style=None):
70        self.anchor = anchor
71        self.tag = tag
72        self.value = value
73        self.start_mark = start_mark
74        self.end_mark = end_mark
75        self.implicit = implicit
76        self.style = style
77
78class SequenceStartEvent(CollectionStartEvent):
[118]79    pass
80
[130]81class SequenceEndEvent(CollectionEndEvent):
[118]82    pass
83
[130]84class MappingStartEvent(CollectionStartEvent):
[118]85    pass
86
[130]87class MappingEndEvent(CollectionEndEvent):
[51]88    pass
89
Note: See TracBrowser for help on using the repository browser.