Skip to content

Commit

Permalink
Fix jupyter_client warning
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Sep 9, 2021
1 parent 49d5772 commit cee81d4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
11 changes: 8 additions & 3 deletions jupyter_server/base/zmqhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

import tornado
from ipython_genutils.py3compat import cast_unicode
from jupyter_client.jsonutil import date_default
try:
from jupyter_client.jsonutil import json_default
except ImportError:
from jupyter_client.jsonutil import (
date_default as json_default
)
from jupyter_client.jsonutil import extract_dates
from jupyter_client.session import Session
from tornado import ioloop
Expand Down Expand Up @@ -39,7 +44,7 @@ def serialize_binary_message(msg):
buffers = list(msg.pop("buffers"))
if sys.version_info < (3, 4):
buffers = [x.tobytes() for x in buffers]
bmsg = json.dumps(msg, default=date_default).encode("utf8")
bmsg = json.dumps(msg, default=json_default).encode("utf8")
buffers.insert(0, bmsg)
nbufs = len(buffers)
offsets = [4 * (nbufs + 1)]
Expand Down Expand Up @@ -227,7 +232,7 @@ def _reserialize_reply(self, msg_or_list, channel=None):
buf = serialize_binary_message(msg)
return buf
else:
smsg = json.dumps(msg, default=date_default)
smsg = json.dumps(msg, default=json_default)
return cast_unicode(smsg)

def _on_zmq_reply(self, stream, msg_list):
Expand Down
13 changes: 9 additions & 4 deletions jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# Distributed under the terms of the Modified BSD License.
import json

from jupyter_client.jsonutil import date_default
try:
from jupyter_client.jsonutil import json_default
except ImportError:
from jupyter_client.jsonutil import (
date_default as json_default
)
from tornado import web

from jupyter_server.base.handlers import APIHandler
Expand Down Expand Up @@ -77,7 +82,7 @@ def _finish_model(self, model, location=True):
self.set_header("Location", location)
self.set_header("Last-Modified", model["last_modified"])
self.set_header("Content-Type", "application/json")
self.finish(json.dumps(model, default=date_default))
self.finish(json.dumps(model, default=json_default))

@web.authenticated
async def get(self, path=""):
Expand Down Expand Up @@ -237,15 +242,15 @@ async def get(self, path=""):
"""get lists checkpoints for a file"""
cm = self.contents_manager
checkpoints = await ensure_async(cm.list_checkpoints(path))
data = json.dumps(checkpoints, default=date_default)
data = json.dumps(checkpoints, default=json_default)
self.finish(data)

@web.authenticated
async def post(self, path=""):
"""post creates a new checkpoint"""
cm = self.contents_manager
checkpoint = await ensure_async(cm.create_checkpoint(path))
data = json.dumps(checkpoint, default=date_default)
data = json.dumps(checkpoint, default=json_default)
location = url_path_join(
self.base_url,
"api/contents",
Expand Down
19 changes: 12 additions & 7 deletions jupyter_server/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

from ipython_genutils.py3compat import cast_unicode
from jupyter_client import protocol_version as client_protocol_version
from jupyter_client.jsonutil import date_default
try:
from jupyter_client.jsonutil import json_default
except ImportError:
from jupyter_client.jsonutil import (
date_default as json_default
)
from tornado import gen
from tornado import web
from tornado.concurrent import Future
Expand All @@ -29,7 +34,7 @@ class MainKernelHandler(APIHandler):
async def get(self):
km = self.kernel_manager
kernels = await ensure_async(km.list_kernels())
self.finish(json.dumps(kernels, default=date_default))
self.finish(json.dumps(kernels, default=json_default))

@web.authenticated
async def post(self):
Expand All @@ -45,15 +50,15 @@ async def post(self):
location = url_path_join(self.base_url, "api", "kernels", url_escape(kernel_id))
self.set_header("Location", location)
self.set_status(201)
self.finish(json.dumps(model, default=date_default))
self.finish(json.dumps(model, default=json_default))


class KernelHandler(APIHandler):
@web.authenticated
async def get(self, kernel_id):
km = self.kernel_manager
model = await ensure_async(km.kernel_model(kernel_id))
self.finish(json.dumps(model, default=date_default))
self.finish(json.dumps(model, default=json_default))

@web.authenticated
async def delete(self, kernel_id):
Expand All @@ -79,7 +84,7 @@ async def post(self, kernel_id, action):
self.set_status(500)
else:
model = await ensure_async(km.kernel_model(kernel_id))
self.write(json.dumps(model, default=date_default))
self.write(json.dumps(model, default=json_default))
self.finish()


Expand Down Expand Up @@ -443,7 +448,7 @@ def write_stderr(error_message):
"stream", content={"text": error_message + "\n", "name": "stderr"}, parent=parent
)
msg["channel"] = "iopub"
self.write_message(json.dumps(msg, default=date_default))
self.write_message(json.dumps(msg, default=json_default))

channel = getattr(stream, "channel", None)
msg_type = msg["header"]["msg_type"]
Expand Down Expand Up @@ -610,7 +615,7 @@ def _send_status_message(self, status):
iopub.flush()
msg = self.session.msg("status", {"execution_state": status})
msg["channel"] = "iopub"
self.write_message(json.dumps(msg, default=date_default))
self.write_message(json.dumps(msg, default=json_default))

def on_kernel_restarted(self):
logging.warn("kernel %s restarted", self.kernel_id)
Expand Down
15 changes: 10 additions & 5 deletions jupyter_server/services/sessions/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# Distributed under the terms of the Modified BSD License.
import json

from jupyter_client.jsonutil import date_default
try:
from jupyter_client.jsonutil import json_default
except ImportError:
from jupyter_client.jsonutil import (
date_default as json_default
)
from jupyter_client.kernelspec import NoSuchKernel
from tornado import web

Expand All @@ -21,7 +26,7 @@ async def get(self):
# Return a list of running sessions
sm = self.session_manager
sessions = await ensure_async(sm.list_sessions())
self.finish(json.dumps(sessions, default=date_default))
self.finish(json.dumps(sessions, default=json_default))

@web.authenticated
async def post(self):
Expand Down Expand Up @@ -79,7 +84,7 @@ async def post(self):
location = url_path_join(self.base_url, "api", "sessions", model["id"])
self.set_header("Location", location)
self.set_status(201)
self.finish(json.dumps(model, default=date_default))
self.finish(json.dumps(model, default=json_default))


class SessionHandler(APIHandler):
Expand All @@ -88,7 +93,7 @@ async def get(self, session_id):
# Returns the JSON model for a single session
sm = self.session_manager
model = await sm.get_session(session_id=session_id)
self.finish(json.dumps(model, default=date_default))
self.finish(json.dumps(model, default=json_default))

@web.authenticated
async def patch(self, session_id):
Expand Down Expand Up @@ -142,7 +147,7 @@ async def patch(self, session_id):
# kernel_id changed because we got a new kernel
# shutdown the old one
await ensure_async(km.shutdown_kernel(before["kernel"]["id"]))
self.finish(json.dumps(model, default=date_default))
self.finish(json.dumps(model, default=json_default))

@web.authenticated
async def delete(self, session_id):
Expand Down

0 comments on commit cee81d4

Please sign in to comment.