From b496732a023ab0eab5614a306b95cb7421099da2 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Thu, 15 Aug 2024 18:15:37 +0200 Subject: [PATCH] util/toml: disable unspecified-encoding check --- osbuild/util/toml.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/osbuild/util/toml.py b/osbuild/util/toml.py index 286bbb65..389c0d39 100644 --- a/osbuild/util/toml.py +++ b/osbuild/util/toml.py @@ -8,7 +8,7 @@ from types import ModuleType from typing import Optional # Different modules require different file mode (text vs binary) -toml_modules = { +_toml_modules = { "tomllib": {"mode": "rb"}, # stdlib since 3.11 (read-only) "tomli": {"mode": "rb"}, # EL9+ "toml": {"mode": "r", "encoding": "utf-8"}, # older unmaintained lib, needed for backwards compatibility @@ -18,7 +18,7 @@ toml_modules = { _toml: Optional[ModuleType] = None _rargs: dict = {} -for module, args in toml_modules.items(): +for module, args in _toml_modules.items(): try: _toml = importlib.import_module(module) _rargs = args @@ -26,10 +26,10 @@ for module, args in toml_modules.items(): except ModuleNotFoundError: pass else: - raise ModuleNotFoundError("No toml module found: " + ", ".join(toml_modules)) + raise ModuleNotFoundError("No toml module found: " + ", ".join(_toml_modules)) # Different modules require different file mode (text vs binary) -tomlw_modules = { +_tomlw_modules = { "tomli_w": {"mode": "wb"}, # EL9+ "toml": {"mode": "w", "encoding": "utf-8"}, # older unmaintained lib, needed for backwards compatibility "pytoml": {"mode": "w", "encoding": "utf-8"}, # deprecated, needed for backwards compatibility (EL8 manifests) @@ -38,7 +38,7 @@ tomlw_modules = { _tomlw: Optional[ModuleType] = None _wargs: dict = {} -for module, args in tomlw_modules.items(): +for module, args in _tomlw_modules.items(): try: _tomlw = importlib.import_module(module) _wargs = args @@ -52,7 +52,7 @@ def load_from_file(path): if _toml is None: raise RuntimeError("no toml module available") - with open(path, **_rargs) as tomlfile: + with open(path, **_rargs) as tomlfile: # pylint: disable=unspecified-encoding return _toml.load(tomlfile) @@ -60,7 +60,7 @@ def dump_to_file(data, path, header=""): if _tomlw is None: raise RuntimeError("no toml module available with write support") - with open(path, **_wargs) as tomlfile: + with open(path, **_wargs) as tomlfile: # pylint: disable=unspecified-encoding if header: _write_comment(tomlfile, header)