Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid use of deprecated zmq.utils.jsonapi #703

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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