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

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

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

RevLine 
[51]1
2class Event:
[122]3    def __init__(self, start_mark=None, end_mark=None):
[116]4        self.start_mark = start_mark
5        self.end_mark = end_mark
[51]6    def __repr__(self):
[122]7        attributes = [key for key in ['anchor', 'tag', 'value']
8                if hasattr(self, key)]
[51]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):
[122]14    def __init__(self, anchor, start_mark=None, end_mark=None):
[51]15        self.anchor = anchor
[116]16        self.start_mark = start_mark
17        self.end_mark = end_mark
[51]18
19class AliasEvent(NodeEvent):
[53]20    pass
[51]21
22class ScalarEvent(NodeEvent):
[127]23    def __init__(self, anchor, tag, value, start_mark=None, end_mark=None,
24            implicit=None, style=None):
[51]25        self.anchor = anchor
26        self.tag = tag
27        self.value = value
[116]28        self.start_mark = start_mark
29        self.end_mark = end_mark
[127]30        self.implicit = implicit
31        self.style = style
[51]32
33class CollectionEvent(NodeEvent):
[127]34    def __init__(self, anchor, tag, start_mark=None, end_mark=None,
35            flow=None, compact=None):
[53]36        self.anchor = anchor
37        self.tag = tag
[116]38        self.start_mark = start_mark
39        self.end_mark = end_mark
[127]40        self.flow = flow
41        self.compact = compact
[51]42
43class SequenceEvent(CollectionEvent):
44    pass
45
46class MappingEvent(CollectionEvent):
47    pass
48
49class CollectionEndEvent(Event):
50    pass
51
[118]52class DocumentStartEvent(Event):
[127]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
[118]63
64class DocumentEndEvent(Event):
65    pass
66
67class StreamStartEvent(Event):
[127]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
[118]73
[51]74class StreamEndEvent(Event):
75    pass
76
Note: See TracBrowser for help on using the repository browser.