Skip to content

Commit

Permalink
Remove the use of simplejson
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
andyhhp committed Feb 12, 2024
1 parent feeb478 commit 57d2eb4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ mypy = [
"mypy-extensions",
"typing_extensions",
"types-mock",
"types-simplejson",
"types-six",
"types-toml",
]
Expand Down
25 changes: 3 additions & 22 deletions xcp/net/ifrename/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 57d2eb4

Please sign in to comment.