diff options
Diffstat (limited to 'constructor.py')
-rw-r--r-- | constructor.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/constructor.py b/constructor.py index cc2ca8c..a7abaf3 100644 --- a/constructor.py +++ b/constructor.py @@ -20,10 +20,11 @@ from ruamel.yaml.compat import (utf8, builtins_module, to_str, PY2, PY3, # NOQA MutableSequence, MutableMapping) from ruamel.yaml.comments import * # NOQA from ruamel.yaml.comments import (CommentedMap, CommentedOrderedMap, CommentedSet, - CommentedKeySeq, CommentedSeq, TaggedScalar, CommentedKeyMap) -from ruamel.yaml.scalarstring import * # NOQA -from ruamel.yaml.scalarstring import (PreservedScalarString, SingleQuotedScalarString, - DoubleQuotedScalarString, ScalarString) + CommentedKeySeq, CommentedSeq, TaggedScalar, + CommentedKeyMap) +from ruamel.yaml.scalarstring import (SingleQuotedScalarString, DoubleQuotedScalarString, + LiteralScalarString, FoldedScalarString, + ScalarString,) from ruamel.yaml.scalarint import ScalarInt, BinaryInt, OctalInt, HexInt, HexCapsInt from ruamel.yaml.scalarfloat import ScalarFloat from ruamel.yaml.timestamp import TimeStamp @@ -1030,10 +1031,24 @@ class RoundTripConstructor(SafeConstructor): ) if node.style == '|' and isinstance(node.value, text_type): - pss = PreservedScalarString(node.value) + pss = LiteralScalarString(node.value) if node.comment and node.comment[1]: pss.comment = node.comment[1][0] # type: ignore return pss + if node.style == '>' and isinstance(node.value, text_type): + fold_positions = [] + idx = None + while True: + idx = node.value.find('\a', None if idx is None else idx + 1) + if idx < 0: + break + fold_positions.append(idx - len(fold_positions)) + pss = FoldedScalarString(node.value.replace('\a', '')) + if node.comment and node.comment[1]: + pss.comment = node.comment[1][0] # type: ignore + if fold_positions: + pss.fold_pos = fold_positions + return pss elif bool(self._preserve_quotes) and isinstance(node.value, text_type): if node.style == "'": return SingleQuotedScalarString(node.value) |