summaryrefslogtreecommitdiff
path: root/representer.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-07-06 23:31:57 +0200
committerAnthon van der Neut <anthon@mnt.org>2016-07-06 23:31:57 +0200
commita990e4568c7f341cc76f5ab572a3089bb1065da4 (patch)
tree437e9b9e007dddc73510e805a554e139a84bef50 /representer.py
parentbc5bd304c273b3c0067c2c8840efedd2bc4fc327 (diff)
downloadruamel.yaml-a990e4568c7f341cc76f5ab572a3089bb1065da4.tar.gz
added optional preservation of quotes around scalars
Diffstat (limited to 'representer.py')
-rw-r--r--representer.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/representer.py b/representer.py
index e3f07ae..7498443 100644
--- a/representer.py
+++ b/representer.py
@@ -605,6 +605,22 @@ class RoundTripRepresenter(SafeRepresenter):
tag = u'tag:yaml.org,2002:str'
return self.represent_scalar(tag, data, style=style)
+ def represent_single_quoted_scalarstring(self, data):
+ tag = None
+ style = "'"
+ if PY2 and not isinstance(data, unicode):
+ data = unicode(data, 'ascii')
+ tag = u'tag:yaml.org,2002:str'
+ return self.represent_scalar(tag, data, style=style)
+
+ def represent_double_quoted_scalarstring(self, data):
+ tag = None
+ style = '"'
+ if PY2 and not isinstance(data, unicode):
+ data = unicode(data, 'ascii')
+ tag = u'tag:yaml.org,2002:str'
+ return self.represent_scalar(tag, data, style=style)
+
def represent_sequence(self, tag, sequence, flow_style=None):
value = []
# if the flow_style is None, the flow style tacked on to the object
@@ -843,6 +859,14 @@ RoundTripRepresenter.add_representer(
PreservedScalarString,
RoundTripRepresenter.represent_preserved_scalarstring)
+RoundTripRepresenter.add_representer(
+ SingleQuotedScalarString,
+ RoundTripRepresenter.represent_single_quoted_scalarstring)
+
+RoundTripRepresenter.add_representer(
+ DoubleQuotedScalarString,
+ RoundTripRepresenter.represent_double_quoted_scalarstring)
+
RoundTripRepresenter.add_representer(CommentedSeq,
RoundTripRepresenter.represent_list)