12
12
# Distributed under the terms of the Modified BSD License.
13
13
import hashlib
14
14
import hmac
15
+ import json
15
16
import logging
16
17
import os
17
18
import pickle
45
46
from traitlets .utils .importstring import import_item # type: ignore
46
47
from zmq .eventloop .ioloop import IOLoop
47
48
from zmq .eventloop .zmqstream import ZMQStream
48
- from zmq .utils import jsonapi
49
49
50
50
from jupyter_client import protocol_version
51
51
from jupyter_client .adapter import adapt
@@ -92,16 +92,18 @@ def squash_unicode(obj):
92
92
93
93
94
94
def json_packer (obj ):
95
- return jsonapi .dumps (
95
+ return json .dumps (
96
96
obj ,
97
97
default = json_default ,
98
98
ensure_ascii = False ,
99
99
allow_nan = False ,
100
- )
100
+ ). encode ( "utf8" )
101
101
102
102
103
103
def json_unpacker (s ):
104
- return jsonapi .loads (s )
104
+ if isinstance (s , bytes ):
105
+ s = s .decode ("utf8" , "replace" )
106
+ return json .loads (s )
105
107
106
108
107
109
def pickle_packer (o ):
@@ -589,12 +591,9 @@ def _check_packers(self) -> None:
589
591
try :
590
592
packed = pack (msg_list )
591
593
except Exception as e :
592
- error_msg = "packer '{packer}' could not serialize a simple message: {e}{jsonmsg}"
593
- if self .packer == "json" :
594
- jsonmsg = "\n zmq.utils.jsonapi.jsonmod = %s" % jsonapi .jsonmod
595
- else :
596
- jsonmsg = ""
597
- raise ValueError (error_msg .format (packer = self .packer , e = e , jsonmsg = jsonmsg )) from e
594
+ raise ValueError (
595
+ f"packer '{ self .packer } ' could not serialize a simple message: { e } "
596
+ ) from e
598
597
599
598
# ensure packed message is bytes
600
599
if not isinstance (packed , bytes ):
@@ -605,15 +604,9 @@ def _check_packers(self) -> None:
605
604
unpacked = unpack (packed )
606
605
assert unpacked == msg_list
607
606
except Exception as e :
608
- error_msg = (
609
- "unpacker '{unpacker}' could not handle output from packer '{packer}': {e}{jsonmsg}"
610
- )
611
- if self .packer == "json" :
612
- jsonmsg = "\n zmq.utils.jsonapi.jsonmod = %s" % jsonapi .jsonmod
613
- else :
614
- jsonmsg = ""
615
607
raise ValueError (
616
- error_msg .format (packer = self .packer , unpacker = self .unpacker , e = e , jsonmsg = jsonmsg )
608
+ f"unpacker '{ self .unpacker } ' could not handle output from packer"
609
+ f" '{ self .packer } ': { e } "
617
610
) from e
618
611
619
612
# check datetime support
0 commit comments