source: trunk/packages/pyyaml/lib/yaml/events.py @ 898

Last change on this file since 898 was 898, checked in by hartmans, 16 years ago

Add pyyaml and libyaml packages
backported from lenny.
There is discussion about how these should go in the repository; these are added in this form
in order to make forward progress.

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