11
11
from tornado import gen , web
12
12
13
13
from 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
+ )
15
20
16
21
from notebook .base .handlers import (
17
22
IPythonHandler , APIHandler , path_regex ,
@@ -85,7 +90,7 @@ def _finish_model(self, model, location=True):
85
90
self .set_header ('Location' , location )
86
91
self .set_header ('Last-Modified' , model ['last_modified' ])
87
92
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 ))
89
94
90
95
@web .authenticated
91
96
@gen .coroutine
@@ -107,7 +112,7 @@ def get(self, path=''):
107
112
if content not in {'0' , '1' }:
108
113
raise web .HTTPError (400 , u'Content %r is invalid' % content )
109
114
content = int (content )
110
-
115
+
111
116
model = yield maybe_future (self .contents_manager .get (
112
117
path = path , type = type , format = format , content = content ,
113
118
))
@@ -125,7 +130,7 @@ def patch(self, path=''):
125
130
model = yield maybe_future (cm .update (model , path ))
126
131
validate_model (model , expect_content = False )
127
132
self ._finish_model (model )
128
-
133
+
129
134
@gen .coroutine
130
135
def _copy (self , copy_from , copy_to = None ):
131
136
"""Copy a file, optionally specifying a target directory."""
@@ -146,7 +151,7 @@ def _upload(self, model, path):
146
151
self .set_status (201 )
147
152
validate_model (model , expect_content = False )
148
153
self ._finish_model (model )
149
-
154
+
150
155
@gen .coroutine
151
156
def _new_untitled (self , path , type = '' , ext = '' ):
152
157
"""Create a new, empty untitled entity"""
@@ -155,13 +160,13 @@ def _new_untitled(self, path, type='', ext=''):
155
160
self .set_status (201 )
156
161
validate_model (model , expect_content = False )
157
162
self ._finish_model (model )
158
-
163
+
159
164
@gen .coroutine
160
165
def _save (self , model , path ):
161
166
"""Save an existing file."""
162
- chunk = model .get ("chunk" , None )
167
+ chunk = model .get ("chunk" , None )
163
168
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 )
165
170
model = yield maybe_future (self .contents_manager .save (model , path ))
166
171
validate_model (model , expect_content = False )
167
172
self ._finish_model (model )
@@ -247,7 +252,7 @@ def get(self, path=''):
247
252
"""get lists checkpoints for a file"""
248
253
cm = self .contents_manager
249
254
checkpoints = yield maybe_future (cm .list_checkpoints (path ))
250
- data = json .dumps (checkpoints , default = date_default )
255
+ data = json .dumps (checkpoints , default = json_default )
251
256
self .finish (data )
252
257
253
258
@web .authenticated
@@ -256,7 +261,7 @@ def post(self, path=''):
256
261
"""post creates a new checkpoint"""
257
262
cm = self .contents_manager
258
263
checkpoint = yield maybe_future (cm .create_checkpoint (path ))
259
- data = json .dumps (checkpoint , default = date_default )
264
+ data = json .dumps (checkpoint , default = json_default )
260
265
location = url_path_join (self .base_url , 'api/contents' ,
261
266
url_escape (path ), 'checkpoints' , url_escape (checkpoint ['id' ]))
262
267
self .set_header ('Location' , location )
0 commit comments