81 lines
3.1 KiB
Diff
81 lines
3.1 KiB
Diff
|
|
From 1a1c2a69045b7fd7a60a59e6cbc3ece0e3f8bd75 Mon Sep 17 00:00:00 2001
|
||
|
|
From: wu-leilei <wu18740459704@163.com>
|
||
|
|
Date: Tue, 8 Feb 2022 18:41:00 +0800
|
||
|
|
Subject: [PATCH] py3k
|
||
|
|
|
||
|
|
---
|
||
|
|
anyjson/__init__.py | 20 ++++++++++----------
|
||
|
|
1 file changed, 10 insertions(+), 10 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/anyjson/__init__.py b/anyjson/__init__.py
|
||
|
|
index 1f671be..0fc9ece 100644
|
||
|
|
--- a/anyjson/__init__.py
|
||
|
|
+++ b/anyjson/__init__.py
|
||
|
|
@@ -23,9 +23,9 @@ if sys.version_info[0] == 3:
|
||
|
|
from io import StringIO
|
||
|
|
else:
|
||
|
|
try:
|
||
|
|
- from cStringIO import StringIO # noqa
|
||
|
|
+ from io import StringIO # noqa
|
||
|
|
except ImportError:
|
||
|
|
- from StringIO import StringIO # noqa
|
||
|
|
+ from io import StringIO # noqa
|
||
|
|
|
||
|
|
#: List of known json modules, and the names of their loads/dumps
|
||
|
|
#: methods, as well as the exceptions they throw. Exception can be either
|
||
|
|
@@ -47,7 +47,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
|
||
|
|
@@ -64,9 +64,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"]
|
||
|
|
@@ -85,8 +85,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):
|
||
|
|
@@ -97,8 +97,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
|
||
|
|
|
||
|
|
|
||
|
|
@@ -117,7 +117,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.23.0
|
||
|
|
|