salt.serializers.yamlex

salt.serializers.yamlex

YAMLEX is a format that allows for things like sls files to be more intuitive.

It's an extension of YAML that implements all the salt magic: - it implies omap for any dict like. - it implies that string like data are str, not unicode - ...

For example, the file states.sls has this contents:

foo:
  bar: 42
  baz: [1, 2, 3]

The file can be parsed into Python like this

from salt.serializers import yamlex

with open('state.sls', 'r') as stream:
    obj = yamlex.deserialize(stream)

Check that obj is an OrderedDict

from salt.utils.odict import OrderedDict

assert isinstance(obj, dict)
assert isinstance(obj, OrderedDict)

yamlex __repr__ and __str__ objects' methods render YAML understandable string. It means that they are template friendly.

print '{0}'.format(obj)

returns:

{foo: {bar: 42, baz: [1, 2, 3]}}

and they are still valid YAML:

from salt.serializers import yaml
yml_obj = yaml.deserialize(str(obj))
assert yml_obj == obj

yamlex implements also custom tags:

!aggregate

this tag allows structures aggregation.

For example:

placeholder: !aggregate foo
placeholder: !aggregate bar
placeholder: !aggregate baz

is rendered as

placeholder: [foo, bar, baz]

!reset

this tag flushes the computing value.

placeholder: {!aggregate foo: {foo: 42}}
placeholder: {!aggregate foo: {bar: null}}
!reset placeholder: {!aggregate foo: {baz: inga}}

is roughly equivalent to

placeholder: {!aggregate foo: {baz: inga}}

Document is defacto an aggregate mapping.

class salt.serializers.yamlex.AggregatedMap
class salt.serializers.yamlex.AggregatedSequence(iterable=(), /)
salt.serializers.yamlex.BaseDumper

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

salt.serializers.yamlex.BaseLoader

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

salt.serializers.yamlex.ConstructorError

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

exception salt.serializers.yamlex.DeserializationError(message, line_num=None, buf='', marker='    <======================', trace=None)

Raised when stream of string failed to be deserialized

salt.serializers.yamlex.Dumper

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

salt.serializers.yamlex.Loader

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

class salt.serializers.yamlex.Map

Map aggregation.

salt.serializers.yamlex.MappingNode

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

class salt.serializers.yamlex.OrderedDict
class salt.serializers.yamlex.SLSMap

Ensures that dict str() and repr() are YAML friendly.

>>> mapping = OrderedDict([('a', 'b'), ('c', None)])
>>> print mapping
OrderedDict([('a', 'b'), ('c', None)])

>>> sls_map = SLSMap(mapping)
>>> print sls_map.__str__()
{a: b, c: null}
class salt.serializers.yamlex.SLSString

Ensures that str str() and repr() are YAML friendly.

>>> scalar = str('foo')
>>> print 'foo'
foo

>>> sls_scalar = SLSString(scalar)
>>> print sls_scalar
"foo"
salt.serializers.yamlex.ScannerError

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

class salt.serializers.yamlex.Sequence(iterable=(), /)

Sequence aggregation.

exception salt.serializers.yamlex.SerializationError(message='')

Raised when stream of string failed to be serialized

salt.serializers.yamlex.aggregate(obj_a, obj_b, level=False, map_class=<class 'salt.utils.aggregation.Map'>, sequence_class=<class 'salt.utils.aggregation.Sequence'>)

Merge obj_b into obj_a.

>>> aggregate('first', 'second', True) == ['first', 'second']
True
salt.serializers.yamlex.deserialize(stream_or_string, **options)

Deserialize any string of stream like object into a Python data structure.

Parameters
  • stream_or_string -- stream or string to deserialize.

  • options -- options given to lower yaml module.

salt.serializers.yamlex.merge_recursive(obj_a, obj_b, level=False)

Merge obj_b into obj_a.

salt.serializers.yamlex.serialize(obj, **options)

Serialize Python data to YAML.

Parameters
  • obj -- the data structure to serialize

  • options -- options given to lower yaml module.

salt.serializers.yamlex.yaml

Mock out specified imports.

This allows autodoc to do its thing without having oodles of req'd installed libs. This doesn't work with import * imports.

This Mock class can be configured to return a specific values at specific names, if required.

https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules

Docs for previous releases are available on readthedocs.org.

Latest Salt release: 3002.6

Table of Contents

Previous topic

salt.serializers.yaml

Next topic

state modules