import yaml


def _ordereddict_representer(dumper, data):
    """
    Generate a YAML representation for Python
    ``collections.OrderedDict`` objects.  This converts the ordered
    dictionary into a YAML mapping node, preserving the ordering of
    the dictionary.

    :param dumper: A YAML dumper.
    :type dumper: ``yaml.Dumper``
    :param data: The data to represent.
    :type data: ``collections.OrderedDictionary``

    :returns: A mapping node, with keys in the specified order.
    :rtype: ``yaml.MappingNode``
    """

    return yaml.MappingNode(
        u'tag:yaml.org,2002:map',
        [
            (dumper.represent_data(key), dumper.represent_data(value))
            for key, value in data.items()
        ]
    )