diff --git a/podman/domain/config.py b/podman/domain/config.py index 555ed9d4..24754696 100644 --- a/podman/domain/config.py +++ b/podman/domain/config.py @@ -1,17 +1,18 @@ """Read containers.conf file.""" +import sys import urllib from pathlib import Path from typing import Dict, Optional import xdg.BaseDirectory -try: - import toml -except ImportError: - import pytoml as toml - from podman.api import cached_property +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + class ServiceConnection: """ServiceConnection defines a connection to the Podman service.""" @@ -62,9 +63,8 @@ def __init__(self, path: Optional[str] = None): self.attrs = {} if self.path.exists(): - with self.path.open(encoding='utf-8') as file: - buffer = file.read() - self.attrs = toml.loads(buffer) + with self.path.open("rb") as file: + self.attrs = tomllib.load(file) def __hash__(self) -> int: return hash(tuple(self.path.name)) diff --git a/podman/tests/unit/test_config.py b/podman/tests/unit/test_config.py index 7ecb475a..845cad24 100644 --- a/podman/tests/unit/test_config.py +++ b/podman/tests/unit/test_config.py @@ -9,7 +9,7 @@ class PodmanConfigTestCase(unittest.TestCase): opener = mock.mock_open( - read_data=""" + read_data=b""" [containers] log_size_max = -1 pids_limit = 2048 @@ -50,7 +50,7 @@ def test_connections(self): self.assertEqual(config.services["production"].identity, Path("/home/root/.ssh/id_rsa")) PodmanConfigTestCase.opener.assert_called_with( - Path("/home/developer/containers.conf"), encoding='utf-8' + Path("/home/developer/containers.conf"), "rb" ) diff --git a/podman/tests/unit/test_podmanclient.py b/podman/tests/unit/test_podmanclient.py index 66a739cf..916932de 100644 --- a/podman/tests/unit/test_podmanclient.py +++ b/podman/tests/unit/test_podmanclient.py @@ -14,7 +14,7 @@ class PodmanClientTestCase(unittest.TestCase): """Test the PodmanClient() object.""" opener = mock.mock_open( - read_data=""" + read_data=b""" [containers] log_size_max = -1 pids_limit = 2048 @@ -89,7 +89,7 @@ def test_connect(self): # Build path to support tests running as root or a user expected = Path(xdg.BaseDirectory.xdg_config_home) / "containers" / "containers.conf" - PodmanClientTestCase.opener.assert_called_with(expected, encoding="utf-8") + PodmanClientTestCase.opener.assert_called_with(expected, "rb") def test_connect_404(self): with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)): @@ -110,7 +110,7 @@ def test_connect_default(self): # Build path to support tests running as root or a user expected = Path(xdg.BaseDirectory.xdg_config_home) / "containers" / "containers.conf" - PodmanClientTestCase.opener.assert_called_with(expected, encoding="utf-8") + PodmanClientTestCase.opener.assert_called_with(expected, "rb") if __name__ == '__main__': diff --git a/pyproject.toml b/pyproject.toml index c14dcdc8..b31049e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ requires = [ "requests>=2.24", "setuptools>=46.4", "sphinx", - "toml>=0.10.2", + "tomli>=1.2.3; python_version<'3.11'", "urllib3>=1.24.2", "wheel", ] diff --git a/python-podman.spec.rpkg b/python-podman.spec.rpkg index 5792a311..877ee79b 100644 --- a/python-podman.spec.rpkg +++ b/python-podman.spec.rpkg @@ -49,19 +49,19 @@ Source: {{{ git_dir_pack }}} BuildRequires: git-core BuildRequires: python%{python3_pkgversion}-devel %if %{?old_rhel} -BuildRequires: python%{python3_pkgversion}-pytoml +BuildRequires: python%{python3_pkgversion}-tomli BuildRequires: python%{python3_pkgversion}-pyxdg BuildRequires: python%{python3_pkgversion}-requests BuildRequires: python%{python3_pkgversion}-setuptools -Requires: python%{python3_pkgversion}-pytoml +Requires: python%{python3_pkgversion}-tomli Requires: python%{python3_pkgversion}-pyxdg Requires: python%{python3_pkgversion}-requests %else BuildRequires: pyproject-rpm-macros %endif %if 0%{?fedora} <= 35 && ! 0%{?rhel} -BuildRequires: python%{python3_pkgversion}-toml -Requires: python%{python3_pkgversion}-toml +BuildRequires: python%{python3_pkgversion}-tomli +Requires: python%{python3_pkgversion}-tomli %endif Provides: %{pypi_name}-py = %{version}-%{release} Summary: %{summary} diff --git a/requirements.txt b/requirements.txt index 5713ef5d..0c7937be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,6 @@ pyxdg>=0.26 requests>=2.24 setuptools sphinx -toml>=0.10.2 +tomli>=1.2.3; python_version<'3.11' urllib3>=1.24.2 wheel diff --git a/setup.cfg b/setup.cfg index 73550cfc..f0f469cb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,7 +36,7 @@ test_suite = install_requires = pyxdg>=0.26 requests>=2.24 - toml>=0.10.2 + tomli>=1.2.3; python_version<'3.11' urllib3>=1.24.2 # typing_extensions are included for RHEL 8.5