Skip to content

Commit

Permalink
Merge pull request #703 from minrk/stdlib-json
Browse files Browse the repository at this point in the history
avoid use of deprecated zmq.utils.jsonapi
  • Loading branch information
Steven Silvester authored Sep 29, 2021
2 parents 0aaa6fa + 460d1a5 commit e379bf9
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Distributed under the terms of the Modified BSD License.
import hashlib
import hmac
import json
import logging
import os
import pickle
Expand Down Expand Up @@ -45,7 +46,6 @@
from traitlets.utils.importstring import import_item # type: ignore
from zmq.eventloop.ioloop import IOLoop
from zmq.eventloop.zmqstream import ZMQStream
from zmq.utils import jsonapi

from jupyter_client import protocol_version
from jupyter_client.adapter import adapt
Expand Down Expand Up @@ -92,16 +92,18 @@ def squash_unicode(obj):


def json_packer(obj):
return jsonapi.dumps(
return json.dumps(
obj,
default=json_default,
ensure_ascii=False,
allow_nan=False,
)
).encode("utf8")


def json_unpacker(s):
return jsonapi.loads(s)
if isinstance(s, bytes):
s = s.decode("utf8", "replace")
return json.loads(s)


def pickle_packer(o):
Expand Down Expand Up @@ -589,12 +591,9 @@ def _check_packers(self) -> None:
try:
packed = pack(msg_list)
except Exception as e:
error_msg = "packer '{packer}' could not serialize a simple message: {e}{jsonmsg}"
if self.packer == "json":
jsonmsg = "\nzmq.utils.jsonapi.jsonmod = %s" % jsonapi.jsonmod
else:
jsonmsg = ""
raise ValueError(error_msg.format(packer=self.packer, e=e, jsonmsg=jsonmsg)) from e
raise ValueError(
f"packer '{self.packer}' could not serialize a simple message: {e}"
) from e

# ensure packed message is bytes
if not isinstance(packed, bytes):
Expand All @@ -605,15 +604,9 @@ def _check_packers(self) -> None:
unpacked = unpack(packed)
assert unpacked == msg_list
except Exception as e:
error_msg = (
"unpacker '{unpacker}' could not handle output from packer '{packer}': {e}{jsonmsg}"
)
if self.packer == "json":
jsonmsg = "\nzmq.utils.jsonapi.jsonmod = %s" % jsonapi.jsonmod
else:
jsonmsg = ""
raise ValueError(
error_msg.format(packer=self.packer, unpacker=self.unpacker, e=e, jsonmsg=jsonmsg)
f"unpacker '{self.unpacker}' could not handle output from packer"
f" '{self.packer}': {e}"
) from e

# check datetime support
Expand Down

0 comments on commit e379bf9

Please sign in to comment.