1111from tornado import gen , web
1212
1313from notebook .utils import maybe_future , url_path_join , url_escape
14- from jupyter_client .jsonutil import date_default
14+ try :
15+ from jupyter_client .jsonutil import json_default
16+ except ImportError :
17+ from jupyter_client .jsonutil import (
18+ date_default as json_default
19+ )
1520
1621from notebook .base .handlers import (
1722 IPythonHandler , APIHandler , path_regex ,
@@ -85,7 +90,7 @@ def _finish_model(self, model, location=True):
8590 self .set_header ('Location' , location )
8691 self .set_header ('Last-Modified' , model ['last_modified' ])
8792 self .set_header ('Content-Type' , 'application/json' )
88- self .finish (json .dumps (model , default = date_default ))
93+ self .finish (json .dumps (model , default = json_default ))
8994
9095 @web .authenticated
9196 @gen .coroutine
@@ -107,7 +112,7 @@ def get(self, path=''):
107112 if content not in {'0' , '1' }:
108113 raise web .HTTPError (400 , u'Content %r is invalid' % content )
109114 content = int (content )
110-
115+
111116 model = yield maybe_future (self .contents_manager .get (
112117 path = path , type = type , format = format , content = content ,
113118 ))
@@ -125,7 +130,7 @@ def patch(self, path=''):
125130 model = yield maybe_future (cm .update (model , path ))
126131 validate_model (model , expect_content = False )
127132 self ._finish_model (model )
128-
133+
129134 @gen .coroutine
130135 def _copy (self , copy_from , copy_to = None ):
131136 """Copy a file, optionally specifying a target directory."""
@@ -146,7 +151,7 @@ def _upload(self, model, path):
146151 self .set_status (201 )
147152 validate_model (model , expect_content = False )
148153 self ._finish_model (model )
149-
154+
150155 @gen .coroutine
151156 def _new_untitled (self , path , type = '' , ext = '' ):
152157 """Create a new, empty untitled entity"""
@@ -155,13 +160,13 @@ def _new_untitled(self, path, type='', ext=''):
155160 self .set_status (201 )
156161 validate_model (model , expect_content = False )
157162 self ._finish_model (model )
158-
163+
159164 @gen .coroutine
160165 def _save (self , model , path ):
161166 """Save an existing file."""
162- chunk = model .get ("chunk" , None )
167+ chunk = model .get ("chunk" , None )
163168 if not chunk or chunk == - 1 : # Avoid tedious log information
164- self .log .info (u"Saving file at %s" , path )
169+ self .log .info (u"Saving file at %s" , path )
165170 model = yield maybe_future (self .contents_manager .save (model , path ))
166171 validate_model (model , expect_content = False )
167172 self ._finish_model (model )
@@ -247,7 +252,7 @@ def get(self, path=''):
247252 """get lists checkpoints for a file"""
248253 cm = self .contents_manager
249254 checkpoints = yield maybe_future (cm .list_checkpoints (path ))
250- data = json .dumps (checkpoints , default = date_default )
255+ data = json .dumps (checkpoints , default = json_default )
251256 self .finish (data )
252257
253258 @web .authenticated
@@ -256,7 +261,7 @@ def post(self, path=''):
256261 """post creates a new checkpoint"""
257262 cm = self .contents_manager
258263 checkpoint = yield maybe_future (cm .create_checkpoint (path ))
259- data = json .dumps (checkpoint , default = date_default )
264+ data = json .dumps (checkpoint , default = json_default )
260265 location = url_path_join (self .base_url , 'api/contents' ,
261266 url_escape (path ), 'checkpoints' , url_escape (checkpoint ['id' ]))
262267 self .set_header ('Location' , location )
0 commit comments