comparison env/lib/python3.7/site-packages/ruamel/yaml/nodes.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 # coding: utf-8
2
3 from __future__ import print_function
4
5 import sys
6 from .compat import string_types
7
8 if False: # MYPY
9 from typing import Dict, Any, Text # NOQA
10
11
12 class Node(object):
13 __slots__ = 'tag', 'value', 'start_mark', 'end_mark', 'comment', 'anchor'
14
15 def __init__(self, tag, value, start_mark, end_mark, comment=None, anchor=None):
16 # type: (Any, Any, Any, Any, Any, Any) -> None
17 self.tag = tag
18 self.value = value
19 self.start_mark = start_mark
20 self.end_mark = end_mark
21 self.comment = comment
22 self.anchor = anchor
23
24 def __repr__(self):
25 # type: () -> str
26 value = self.value
27 # if isinstance(value, list):
28 # if len(value) == 0:
29 # value = '<empty>'
30 # elif len(value) == 1:
31 # value = '<1 item>'
32 # else:
33 # value = '<%d items>' % len(value)
34 # else:
35 # if len(value) > 75:
36 # value = repr(value[:70]+u' ... ')
37 # else:
38 # value = repr(value)
39 value = repr(value)
40 return '%s(tag=%r, value=%s)' % (self.__class__.__name__, self.tag, value)
41
42 def dump(self, indent=0):
43 # type: (int) -> None
44 if isinstance(self.value, string_types):
45 sys.stdout.write(
46 '{}{}(tag={!r}, value={!r})\n'.format(
47 ' ' * indent, self.__class__.__name__, self.tag, self.value
48 )
49 )
50 if self.comment:
51 sys.stdout.write(' {}comment: {})\n'.format(' ' * indent, self.comment))
52 return
53 sys.stdout.write(
54 '{}{}(tag={!r})\n'.format(' ' * indent, self.__class__.__name__, self.tag)
55 )
56 if self.comment:
57 sys.stdout.write(' {}comment: {})\n'.format(' ' * indent, self.comment))
58 for v in self.value:
59 if isinstance(v, tuple):
60 for v1 in v:
61 v1.dump(indent + 1)
62 elif isinstance(v, Node):
63 v.dump(indent + 1)
64 else:
65 sys.stdout.write('Node value type? {}\n'.format(type(v)))
66
67
68 class ScalarNode(Node):
69 """
70 styles:
71 ? -> set() ? key, no value
72 " -> double quoted
73 ' -> single quoted
74 | -> literal style
75 > -> folding style
76 """
77
78 __slots__ = ('style',)
79 id = 'scalar'
80
81 def __init__(
82 self, tag, value, start_mark=None, end_mark=None, style=None, comment=None, anchor=None
83 ):
84 # type: (Any, Any, Any, Any, Any, Any, Any) -> None
85 Node.__init__(self, tag, value, start_mark, end_mark, comment=comment, anchor=anchor)
86 self.style = style
87
88
89 class CollectionNode(Node):
90 __slots__ = ('flow_style',)
91
92 def __init__(
93 self,
94 tag,
95 value,
96 start_mark=None,
97 end_mark=None,
98 flow_style=None,
99 comment=None,
100 anchor=None,
101 ):
102 # type: (Any, Any, Any, Any, Any, Any, Any) -> None
103 Node.__init__(self, tag, value, start_mark, end_mark, comment=comment)
104 self.flow_style = flow_style
105 self.anchor = anchor
106
107
108 class SequenceNode(CollectionNode):
109 __slots__ = ()
110 id = 'sequence'
111
112
113 class MappingNode(CollectionNode):
114 __slots__ = ('merge',)
115 id = 'mapping'
116
117 def __init__(
118 self,
119 tag,
120 value,
121 start_mark=None,
122 end_mark=None,
123 flow_style=None,
124 comment=None,
125 anchor=None,
126 ):
127 # type: (Any, Any, Any, Any, Any, Any, Any) -> None
128 CollectionNode.__init__(
129 self, tag, value, start_mark, end_mark, flow_style, comment, anchor
130 )
131 self.merge = None