Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/toml.py @ 195:28e6c1413947
Added support for TOML style configuration files
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 03 May 2019 21:51:09 +0200 |
| parents | |
| children | b3b5ed34d180 |
comparison
equal
deleted
inserted
replaced
| 194:0d8dd58afc44 | 195:28e6c1413947 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 #- | |
| 3 # :Copyright: (c) 2015-2019, Franz Glasner. All rights reserved. | |
| 4 # :License: 3-clause BSD. See LICENSE.txt for details. | |
| 5 #- | |
| 6 """Read TOML style configuration files. | |
| 7 | |
| 8 """ | |
| 9 | |
| 10 from __future__ import division, absolute_import, print_function | |
| 11 | |
| 12 | |
| 13 __all__ = ["load"] | |
| 14 | |
| 15 | |
| 16 import io | |
| 17 try: | |
| 18 from collections import OrderedDict as DictImpl | |
| 19 except ImportError: | |
| 20 try: | |
| 21 from ordereddict import OrderedDict as DictImpl | |
| 22 except ImportError: | |
| 23 DictImpl = dict | |
| 24 | |
| 25 import toml | |
| 26 | |
| 27 from .compat import u2fs | |
| 28 | |
| 29 | |
| 30 def load(filename, encoding="utf-8"): | |
| 31 """Load a single TOML file with name `filename` and encoding `encoding`. | |
| 32 | |
| 33 .. note:: The TOML standard requires that all TOML files are UTF-8 | |
| 34 encoded. | |
| 35 | |
| 36 """ | |
| 37 with io.open(u2fs(filename), mode="rt", encoding=encoding) as tfp: | |
| 38 return toml.loads(tfp.read(), _dict=DictImpl) |
