Is it possible to fix a valid YAML with bindings / links disabled by Ruby or Python?

Is it possible to disable the creation of bindings and links (and efficiently enumerate redundant data explicitly) either in PyYAMLor in Ruby Psych?

I may have missed something while searching on the Internet, but it seems that there are Psychnot many options, and I could not determine if this allows PyYAML.

The rationale is that I have to serialize some data and transfer it in a human-readable form to a non-really technical employee for manual verification. Some data is redundant, but I need it to be explicitly stated for readability (bindings and links are a good concept of efficiency, but not for readability).

Ruby and Python are my selection tools, but if there is some other fairly simple way to β€œexpand” YAML documents, it can just do.

+5
source share
1 answer

I found this related ticket on the PyYAML website ( http://pyyaml.org/ticket/91 ), it looks like bindings can be disabled using a custom line dump truck:

import yaml

class ExplicitDumper(yaml.SafeDumper):
    """
    A dumper that will never emit aliases.
    """

    def ignore_aliases(self, data):
        return True

So, for example, the following outputs can be achieved using a standard dump truck and a new explicit dump truck:

>>> yaml.dump([1L, 1L])
"[&id001 !!python/long '1', *id001]\n"

>>> yaml.dump([1L, 1L], Dumper=ExplicitDumper)
'[1, 1]\n'

You can configure additional properties to ensure print privacy, etc. in a call yaml.dump(...).

+8
source

All Articles