summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-08-14 20:44:09 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-08-14 20:44:09 +0200
commit4c7259963b3f1bd92e7f5a863a737ef008e0e6dd (patch)
tree8b163f23fd56eac04246417cef96ca927a561ca2 /main.py
parent21c1662a4c8367e1ce48811f78bcfe2830d06d58 (diff)
downloadruamel.yaml-4c7259963b3f1bd92e7f5a863a737ef008e0e6dd.tar.gz
fix issue #51: separate indent levels for mappings and sequences0.15.29
**When this resolves the reported problem, please close this issue**
Diffstat (limited to 'main.py')
-rw-r--r--main.py53
1 files changed, 47 insertions, 6 deletions
diff --git a/main.py b/main.py
index 949191d..74d2507 100644
--- a/main.py
+++ b/main.py
@@ -110,10 +110,14 @@ class YAML(object):
'typ "{}"not recognised (need to install plug-in?)'.format(self.typ))
self.stream = None
self.canonical = None
- self.indent = None
+ self.old_indent = None
self.width = None
self.line_break = None
- self.block_seq_indent = None
+
+ self.map_indent = None
+ self.sequence_indent = None
+ self.sequence_dash_offset = 0
+
self.top_level_colon_align = None
self.prefix_colon = None
self.version = None
@@ -198,12 +202,19 @@ class YAML(object):
attr = '_' + sys._getframe().f_code.co_name
if not hasattr(self, attr):
if self.Emitter is not CEmitter:
- setattr(self, attr, self.Emitter(
+ _emitter = self.Emitter(
None, canonical=self.canonical,
- indent=self.indent, width=self.width,
+ indent=self.old_indent, width=self.width,
allow_unicode=self.allow_unicode, line_break=self.line_break,
- block_seq_indent=self.block_seq_indent,
- dumper=self))
+ dumper=self)
+ setattr(self, attr, _emitter)
+ if self.map_indent is not None:
+ _emitter.best_map_indent = self.map_indent
+ if self.sequence_indent is not None:
+ _emitter.best_sequence_indent = self.sequence_indent
+ if self.sequence_dash_offset is not None:
+ _emitter.sequence_dash_offset = self.sequence_dash_offset
+ # _emitter.block_seq_indent = self.sequence_dash_offset
else:
if getattr(self, '_stream', None) is None:
# wait for the stream
@@ -490,6 +501,36 @@ class YAML(object):
self.constructor.add_constructor(tag, f_y)
+ # ### backwards compatibility
+ def _indent(self, mapping=None, sequence=None, offset=None):
+ # type: (Any, Any, Any) -> None
+ if mapping is not None:
+ self.map_indent = mapping
+ if sequence is not None:
+ self.sequence_indent = sequence
+ if offset is not None:
+ self.sequence_dash_offset = offset
+
+ @property
+ def indent(self):
+ # type: () -> Any
+ return self._indent
+
+ @indent.setter
+ def indent(self, val):
+ # type: (Any) -> None
+ self.old_indent = val
+
+ @property
+ def block_seq_indent(self):
+ # type: () -> Any
+ return self.sequence_dash_offset
+
+ @block_seq_indent.setter
+ def block_seq_indent(self, val):
+ # type: (Any) -> None
+ self.sequence_dash_offset = val
+
def yaml_object(yml):
# type: (Any) -> Any