view configmix/toml.py @ 199:852f6c0c9298

Need a PyYAML version < 4. PyYAML 5 is out -- which dropped support for Python 2.6. Because we support Python 2.6 stay at version 3.
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 04 May 2019 14:23:09 +0200
parents 28e6c1413947
children b3b5ed34d180
line wrap: on
line source

# -*- coding: utf-8 -*-
#-
# :Copyright: (c) 2015-2019, Franz Glasner. All rights reserved.
# :License:   3-clause BSD. 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)