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

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

Major refactoring.

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