# -*- coding: utf-8 -*-
'''
    salt.utils.yamldumper
    ~~~~~~~~~~~~~~~~~~~~~

'''
# pylint: disable=W0232
#         class has no __init__ method

from __future__ import absolute_import
try:
    from yaml import CDumper as Dumper
    from yaml import CSafeDumper as SafeDumper
except ImportError:
    from yaml import Dumper
    from yaml import SafeDumper

import yaml
import collections
from salt.utils.odict import OrderedDict

try:
    from ioflo.aid.odicting import odict  # pylint: disable=E0611
    HAS_IOFLO = True
except ImportError:
    odict = None
    HAS_IOFLO = False


class OrderedDumper(Dumper):
    '''
    A YAML dumper that represents python OrderedDict as simple YAML map.
    '''


class SafeOrderedDumper(SafeDumper):
    '''
    A YAML safe dumper that represents python OrderedDict as simple YAML map.
    '''


def represent_ordereddict(dumper, data):
    return dumper.represent_dict(list(data.items()))


OrderedDumper.add_representer(OrderedDict, represent_ordereddict)
SafeOrderedDumper.add_representer(OrderedDict, represent_ordereddict)

OrderedDumper.add_representer(
    collections.defaultdict,
    yaml.representer.SafeRepresenter.represent_dict
)
SafeOrderedDumper.add_representer(
    collections.defaultdict,
    yaml.representer.SafeRepresenter.represent_dict
)

if HAS_IOFLO:
    OrderedDumper.add_representer(odict, represent_ordereddict)
    SafeOrderedDumper.add_representer(odict, represent_ordereddict)


def safe_dump(data, stream=None, **kwargs):
    '''
    Use a custom dumper to ensure that defaultdict and OrderedDict are
    represented properly
    '''
    return yaml.dump(data, stream, Dumper=SafeOrderedDumper, **kwargs)

@@ -579,16 +579,338 @@
 False%0A%0A%0A
+class IndentMixin(object):%0A    '''%0A    Mixin that improves YAML dumped list readability%0A    by indenting them by two spaces,%0A    instead of being flush with the key they are under.%0A    '''%0A%0A    def increase_indent(self, flow=False, indentless=False):%0A        return super(IndentMixin, self).increase_indent(flow, False)%0A%0A%0A
 class Or
@@ -922,32 +922,32 @@
 Dumper(Dumper):%0A
-
     '''%0A    A YA
@@ -1154,16 +1154,228 @@
   '''%0A%0A%0A
+class IndentedSafeOrderedDumper(IndentMixin, SafeOrderedDumper):%0A    '''%0A    A YAML safe dumper that represents python OrderedDict as simple YAML map,%0A    and also indents lists by two spaces.%0A    '''%0A    pass%0A%0A%0A
 def repr
@@ -1910,16 +1910,16 @@
 eddict)%0A
-
     Safe
@@ -1980,16 +1980,235 @@
 dict)%0A%0A%0A
+def get_dumper(dumper_name):%0A    return %7B%0A        'OrderedDumper': OrderedDumper,%0A        'SafeOrderedDumper': SafeOrderedDumper,%0A        'IndentedSafeOrderedDumper': IndentedSafeOrderedDumper,%0A    %7D.get(dumper_name)%0A%0A%0A
 def safe

Add new YAML dumper with improved readability