summaryrefslogtreecommitdiff
path: root/lib/yaml/nodes.py
blob: 377d24c9880564bcf1e4199148a2c827d9396eed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

class Node:
    def __init__(self, tag, value, start_marker, end_marker):
        self.tag = tag
        self.value = value
        self.start_marker = start_marker
        self.end_marker = end_marker
    def __repr__(self):
        value = self.value
        if isinstance(value, list):
            if len(value) == 0:
                value = '<empty>'
            elif len(value) == 1:
                value = '<1 item>'
            else:
                value = '<%d items>' % len(value)
        else:
            if len(value) > 75:
                value = repr(value[:70]+u' ... ')
            else:
                value = repr(value)
        return '%s(tag=%r, value=%s)' % (self.__class__.__name__, self.tag, value)

class ScalarNode(Node):
    id = 'scalar'

class CollectionNode(Node):
    pass

class SequenceNode(CollectionNode):
    id = 'sequence'

class MappingNode(CollectionNode):
    id = 'mapping'