'Force string quoting, while saving flow style

I have data, that looks somewhat like this

data = {"a": {"a": "0.1.2", "b": "0.2.3"}, "c": 3}

and I want it to create a YAML document, that should look like this

a: {a: "0.1.2", b: "0.2.3"}
c: 3

so, by default we will have

yaml = ruamel.yaml.YAML()
data = {"a": {"a": "0.1.2", "b": "0.2.3"}, "c": 3}
yaml.dump(data, sys.stdout)

which gives us this

a:
  a: 0.1.2
  b: 0.2.3
c: 3

but I need the dict to be inline and the strings to be quoted.
For inline dict I can use

yaml.default_flow_style = None

almost there

a: {a: 0.1.2, b: 0.2.3}
c: 3

and for strings

from ruamel.yaml.scalarstring import SingleQuotedScalarString as dq

(I could also use yaml.default_style = '"' but it also quotes the keys and doesn't help with the flow)

the thing is double quotes somehow break the flow:

yaml = ruamel.yaml.YAML()
yaml.default_flow_style = None
data = {"a": {"a": dq("0.1.2"), "b": dq("0.2.3")}, "c": 3}
yaml.dump(data, sys.stdout)

gives me this back

a:
  a: "0.1.2"
  b: "0.2.3"
c: 3

How can I get the desired output?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source