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

Revision 133, 2.6 KB checked in by xi, 9 years ago (diff)

Implement yaml.dump().

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