From 57d2eb41c29b33b268b52ed67bfe295d34c32f8a Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Mon, 12 Feb 2024 10:48:20 +0000 Subject: [PATCH] Remove the use of simplejson This logic dates back to the XenServer 6.x days using Python 2.4. simplejson was merged into the Python 2.5 standard library. Signed-off-by: Andrew Cooper --- pyproject.toml | 1 - xcp/net/ifrename/dynamic.py | 25 +++---------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 36007f45..845d6c98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,6 @@ mypy = [ "mypy-extensions", "typing_extensions", "types-mock", - "types-simplejson", "types-six", "types-toml", ] diff --git a/xcp/net/ifrename/dynamic.py b/xcp/net/ifrename/dynamic.py index f49147d7..9cf2a9c8 100644 --- a/xcp/net/ifrename/dynamic.py +++ b/xcp/net/ifrename/dynamic.py @@ -31,19 +31,11 @@ from __future__ import unicode_literals from os.path import exists as pathexists +import json __version__ = "1.0.0" __author__ = "Andrew Cooper" -try: - import json -except ImportError: - try: - import simplejson as json # type: ignore[no-redef] # pragma: no cover - # The installer has no json. In the meantime, there is a workaround - except ImportError: - pass - from xcp.compat import open_with_codec_handling from xcp.logger import LOG @@ -126,10 +118,6 @@ def load_and_parse(self): except ValueError: LOG.warning("Dynamic rules appear to be corrupt") return False - # The installer has no json. - except NameError: - LOG.warning("Module json not available. Cant parse dynamic rules.") - return False if "lastboot" in info: for entry in info["lastboot"]: @@ -264,15 +252,8 @@ def validate(entry): lastboot = [x for x in self.lastboot if validate(x)] old = [x for x in self.old if validate(x)] - try: - res += json.dumps({"lastboot": lastboot, "old": old}, - indent=4, sort_keys=True) - # Installer has no json. This will do in the meantime - except NameError: - res += ('{"lastboot":%s,"old":%s}' - % ( ("%s" % (lastboot,)).replace("'", '"'), - ("%s" % (old,)).replace("'", '"')) - ) + res += json.dumps({"lastboot": lastboot, "old": old}, + indent=4, sort_keys=True) return res