python-anyjson/fix-py3k.patch
2023-04-10 11:06:47 +08:00

69 lines
2.6 KiB
Diff

From 871ef3aa8060e8cde1d226e452fa3cd20d2dcc41 Mon Sep 17 00:00:00 2001
From: wang--ge <wang__ge@126.com>
Date: Mon, 10 Apr 2023 10:13:54 +0800
Subject: [PATCH] fix py3k
---
anyjson/__init__.py | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/anyjson/__init__.py b/anyjson/__init__.py
index 1630839..d8af338 100644
--- a/anyjson/__init__.py
+++ b/anyjson/__init__.py
@@ -38,7 +38,7 @@ class _JsonImplementation(object):
"""Incapsulates a JSON implementation"""
def __init__(self, modspec):
- modinfo = dict(zip(_fields, modspec))
+ modinfo = dict(list(zip(_fields, modspec)))
if modinfo["modname"] == "cjson":
import warnings
@@ -55,9 +55,9 @@ class _JsonImplementation(object):
self._encode_error = modinfo["encerror"]
self._decode_error = modinfo["decerror"]
- if isinstance(modinfo["encerror"], basestring):
+ if isinstance(modinfo["encerror"], str):
self._encode_error = getattr(module, modinfo["encerror"])
- if isinstance(modinfo["decerror"], basestring):
+ if isinstance(modinfo["decerror"], str):
self._decode_error = getattr(module, modinfo["decerror"])
self.name = modinfo["modname"]
@@ -76,8 +76,8 @@ class _JsonImplementation(object):
TypeError if the object could not be serialized."""
try:
return self._encode(data)
- except self._encode_error, exc:
- raise TypeError, TypeError(*exc.args), sys.exc_info()[2]
+ except self._encode_error as exc:
+ raise TypeError(TypeError(*exc.args)).with_traceback(sys.exc_info()[2])
serialize = dumps
def loads(self, s):
@@ -88,8 +88,8 @@ class _JsonImplementation(object):
if self._filedecode and not isinstance(s, basestring):
return self._filedecode(StringIO(s))
return self._decode(s)
- except self._decode_error, exc:
- raise ValueError, ValueError(*exc.args), sys.exc_info()[2]
+ except self._decode_error as exc:
+ raise ValueError(ValueError(*exc.args)).with_traceback(sys.exc_info()[2])
deserialize = loads
@@ -108,7 +108,7 @@ if __name__ == "__main__":
# We do NOT try to load a compatible module because that may throw an
# exception, which renders the package uninstallable with easy_install
# (It trys to execfile the script when installing, to make sure it works)
- print "Running anyjson as a stand alone script is not supported"
+ print("Running anyjson as a stand alone script is not supported")
sys.exit(1)
else:
for modspec in _modules:
--
2.33.0