from typing import TextIO
from typing import Dict
from typing import OrderedDict
import yaml


def yaml_load(stream: TextIO) -> Dict[str, str]:
    """
    Load a yaml from a file pointer in an ordered way.

    :param stream: the file pointer
    :return: the yaml
    """
    # for pydocstyle
    def ordered_load(stream: TextIO, object_pairs_hook=OrderedDict):
        class OrderedLoader(yaml.SafeLoader):
            """A wrapper for safe yaml loader."""

            pass

        def construct_mapping(loader, node):
            loader.flatten_mapping(node)
            return object_pairs_hook(loader.construct_pairs(node))

        OrderedLoader.add_constructor(
            yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, construct_mapping
        )
        return yaml.load(stream, OrderedLoader)  # nosec

    return ordered_load(stream)