view configmix/toml.py @ 633:9ab72688278b v0.20.4

+++++ v0.20.4
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 17 Jan 2022 09:17:30 +0100
parents f454889e41fa
children 211288645f02
line wrap: on
line source

# -*- coding: utf-8 -*-
# :-
# :Copyright: (c) 2015-2022, Franz Glasner. All rights reserved.
# :License:   BSD-3-Clause. See LICENSE.txt for details.
# :-
"""Read TOML style configuration files.

"""

from __future__ import division, absolute_import, print_function


__all__ = ["load"]


import io
try:
    from collections import OrderedDict as DictImpl
except ImportError:
    try:
        from ordereddict import OrderedDict as DictImpl
    except ImportError:
        DictImpl = dict

import toml

from .compat import u2fs


def load(filename, encoding="utf-8"):
    """Load a single TOML file with name `filename` and encoding `encoding`.

    .. note:: The TOML standard requires that all TOML files are UTF-8
              encoded.

    """
    with io.open(u2fs(filename), mode="rt", encoding=encoding) as tfp:
        return toml.loads(tfp.read(), _dict=DictImpl)