annotate configmix/toml.py @ 284:4aaf74858d07

Some links to AWS docu into the aws moduleSome links to AWS docu into the aws moduleSome links to AWS docu into the aws moduleSome links to AWS docu into the aws moduleSome links to AWS docu into the aws moduleSome links to AWS docu into the aws moduleSome links to AWS docu into the aws moduleSome links to AWS docu into the aws module
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 07 Dec 2020 01:59:11 +0100
parents 13711ba8e81e
children eed16a1ec8f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
195
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
208
bbe8513ea649 Handle flake8 E265 "block comment should start with '# ': use '# :-' instead of '#-' to mark copyright and license comments
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
2 # :-
237
13711ba8e81e Adjust copyright year to 2020
Franz Glasner <fzglas.hg@dom66.de>
parents: 208
diff changeset
3 # :Copyright: (c) 2015-2020, Franz Glasner. All rights reserved.
195
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 # :License: 3-clause BSD. See LICENSE.txt for details.
208
bbe8513ea649 Handle flake8 E265 "block comment should start with '# ': use '# :-' instead of '#-' to mark copyright and license comments
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
5 # :-
195
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 """Read TOML style configuration files.
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 """
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10 from __future__ import division, absolute_import, print_function
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13 __all__ = ["load"]
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 import io
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17 try:
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 from collections import OrderedDict as DictImpl
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19 except ImportError:
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 try:
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21 from ordereddict import OrderedDict as DictImpl
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22 except ImportError:
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 DictImpl = dict
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 import toml
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 from .compat import u2fs
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30 def load(filename, encoding="utf-8"):
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
31 """Load a single TOML file with name `filename` and encoding `encoding`.
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
32
207
b3b5ed34d180 Handle most flake8 errors and warnings.
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
33 .. note:: The TOML standard requires that all TOML files are UTF-8
195
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
34 encoded.
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 """
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37 with io.open(u2fs(filename), mode="rt", encoding=encoding) as tfp:
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38 return toml.loads(tfp.read(), _dict=DictImpl)