summaryrefslogtreecommitdiff
path: root/scalarstring.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-11-09 10:47:11 +0100
committerAnthon van der Neut <anthon@mnt.org>2018-11-09 10:47:11 +0100
commit68ea6b9ef755296c169b5416fe46ac48250e3c62 (patch)
tree8a44637378f20053b3c22ed342bdb2d13805dc97 /scalarstring.py
parent11e092f5746f4437628a4131ea8727db6c4c5692 (diff)
downloadruamel.yaml-68ea6b9ef755296c169b5416fe46ac48250e3c62.tar.gz
fix issue #194 object attributes always sorted0.15.77
Test for this issue in: https://bitbucket.org/ruamel/yaml.data/src/default/object/control_base_representer_mapping_sort.yaml *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))*
Diffstat (limited to 'scalarstring.py')
-rw-r--r--scalarstring.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/scalarstring.py b/scalarstring.py
index 03db72d..c7b1a78 100644
--- a/scalarstring.py
+++ b/scalarstring.py
@@ -3,6 +3,7 @@
from __future__ import print_function, absolute_import, division, unicode_literals
from ruamel.yaml.compat import text_type
+from ruamel.yaml.anchor import Anchor
if False: # MYPY
from typing import Text, Any, Dict, List # NOQA
@@ -20,7 +21,7 @@ __all__ = [
class ScalarString(text_type):
- __slots__ = ()
+ __slots__ = (Anchor.attrib)
def __new__(cls, *args, **kw):
# type: (Any, Any) -> Any
@@ -30,6 +31,26 @@ class ScalarString(text_type):
# type: (Any, Any, int) -> Any
return type(self)((text_type.replace(self, old, new, maxreplace)))
+ @property
+ def anchor(self):
+ # type: () -> Any
+ if not hasattr(self, Anchor.attrib):
+ setattr(self, Anchor.attrib, Anchor())
+ return getattr(self, Anchor.attrib)
+
+ def yaml_anchor(self):
+ # type: () -> Any
+ if not hasattr(self, Anchor.attrib):
+ return None
+ if not self.anchor.always_dump:
+ return None
+ return self.anchor
+
+ def yaml_set_anchor(self, value, always_dump=False):
+ # type: (Any, bool) -> None
+ self.anchor.value = value
+ self.anchor.always_dump = always_dump
+
class LiteralScalarString(ScalarString):
__slots__ = 'comment' # the comment after the | on the first line