10
10
11
11
from tornado import gen , web
12
12
13
- from jupyter_server .utils import url_path_join , url_escape
13
+ from jupyter_server .utils import url_path_join , url_escape , maybe_future
14
14
from jupyter_client .jsonutil import date_default
15
15
16
16
from jupyter_server .base .handlers import (
@@ -107,8 +107,8 @@ def get(self, path=''):
107
107
if content not in {'0' , '1' }:
108
108
raise web .HTTPError (400 , u'Content %r is invalid' % content )
109
109
content = int (content )
110
-
111
- model = yield gen . maybe_future (self .contents_manager .get (
110
+
111
+ model = yield maybe_future (self .contents_manager .get (
112
112
path = path , type = type , format = format , content = content ,
113
113
))
114
114
validate_model (model , expect_content = content )
@@ -122,7 +122,7 @@ def patch(self, path=''):
122
122
model = self .get_json_body ()
123
123
if model is None :
124
124
raise web .HTTPError (400 , u'JSON body missing' )
125
- model = yield gen . maybe_future (cm .update (model , path ))
125
+ model = yield maybe_future (cm .update (model , path ))
126
126
validate_model (model , expect_content = False )
127
127
self ._finish_model (model )
128
128
@@ -133,7 +133,7 @@ def _copy(self, copy_from, copy_to=None):
133
133
copy_from = copy_from ,
134
134
copy_to = copy_to or '' ,
135
135
))
136
- model = yield gen . maybe_future (self .contents_manager .copy (copy_from , copy_to ))
136
+ model = yield maybe_future (self .contents_manager .copy (copy_from , copy_to ))
137
137
self .set_status (201 )
138
138
validate_model (model , expect_content = False )
139
139
self ._finish_model (model )
@@ -142,7 +142,7 @@ def _copy(self, copy_from, copy_to=None):
142
142
def _upload (self , model , path ):
143
143
"""Handle upload of a new file to path"""
144
144
self .log .info (u"Uploading file to %s" , path )
145
- model = yield gen . maybe_future (self .contents_manager .new (model , path ))
145
+ model = yield maybe_future (self .contents_manager .new (model , path ))
146
146
self .set_status (201 )
147
147
validate_model (model , expect_content = False )
148
148
self ._finish_model (model )
@@ -151,7 +151,7 @@ def _upload(self, model, path):
151
151
def _new_untitled (self , path , type = '' , ext = '' ):
152
152
"""Create a new, empty untitled entity"""
153
153
self .log .info (u"Creating new %s in %s" , type or 'file' , path )
154
- model = yield gen . maybe_future (self .contents_manager .new_untitled (path = path , type = type , ext = ext ))
154
+ model = yield maybe_future (self .contents_manager .new_untitled (path = path , type = type , ext = ext ))
155
155
self .set_status (201 )
156
156
validate_model (model , expect_content = False )
157
157
self ._finish_model (model )
@@ -161,8 +161,8 @@ def _save(self, model, path):
161
161
"""Save an existing file."""
162
162
chunk = model .get ("chunk" , None )
163
163
if not chunk or chunk == - 1 : # Avoid tedious log information
164
- self .log .info (u"Saving file at %s" , path )
165
- model = yield gen . maybe_future (self .contents_manager .save (model , path ))
164
+ self .log .info (u"Saving file at %s" , path )
165
+ model = yield maybe_future (self .contents_manager .save (model , path ))
166
166
validate_model (model , expect_content = False )
167
167
self ._finish_model (model )
168
168
@@ -182,11 +182,11 @@ def post(self, path=''):
182
182
183
183
cm = self .contents_manager
184
184
185
- file_exists = yield gen . maybe_future (cm .file_exists (path ))
185
+ file_exists = yield maybe_future (cm .file_exists (path ))
186
186
if file_exists :
187
187
raise web .HTTPError (400 , "Cannot POST to files, use PUT instead." )
188
188
189
- dir_exists = yield gen . maybe_future (cm .dir_exists (path ))
189
+ dir_exists = yield maybe_future (cm .dir_exists (path ))
190
190
if not dir_exists :
191
191
raise web .HTTPError (404 , "No such directory: %s" % path )
192
192
@@ -220,21 +220,21 @@ def put(self, path=''):
220
220
if model :
221
221
if model .get ('copy_from' ):
222
222
raise web .HTTPError (400 , "Cannot copy with PUT, only POST" )
223
- exists = yield gen . maybe_future (self .contents_manager .file_exists (path ))
223
+ exists = yield maybe_future (self .contents_manager .file_exists (path ))
224
224
if exists :
225
- yield gen . maybe_future (self ._save (model , path ))
225
+ yield maybe_future (self ._save (model , path ))
226
226
else :
227
- yield gen . maybe_future (self ._upload (model , path ))
227
+ yield maybe_future (self ._upload (model , path ))
228
228
else :
229
- yield gen . maybe_future (self ._new_untitled (path ))
229
+ yield maybe_future (self ._new_untitled (path ))
230
230
231
231
@web .authenticated
232
232
@gen .coroutine
233
233
def delete (self , path = '' ):
234
234
"""delete a file in the given path"""
235
235
cm = self .contents_manager
236
236
self .log .warning ('delete %s' , path )
237
- yield gen . maybe_future (cm .delete (path ))
237
+ yield maybe_future (cm .delete (path ))
238
238
self .set_status (204 )
239
239
self .finish ()
240
240
@@ -246,7 +246,7 @@ class CheckpointsHandler(APIHandler):
246
246
def get (self , path = '' ):
247
247
"""get lists checkpoints for a file"""
248
248
cm = self .contents_manager
249
- checkpoints = yield gen . maybe_future (cm .list_checkpoints (path ))
249
+ checkpoints = yield maybe_future (cm .list_checkpoints (path ))
250
250
data = json .dumps (checkpoints , default = date_default )
251
251
self .finish (data )
252
252
@@ -255,7 +255,7 @@ def get(self, path=''):
255
255
def post (self , path = '' ):
256
256
"""post creates a new checkpoint"""
257
257
cm = self .contents_manager
258
- checkpoint = yield gen . maybe_future (cm .create_checkpoint (path ))
258
+ checkpoint = yield maybe_future (cm .create_checkpoint (path ))
259
259
data = json .dumps (checkpoint , default = date_default )
260
260
location = url_path_join (self .base_url , 'api/contents' ,
261
261
url_escape (path ), 'checkpoints' , url_escape (checkpoint ['id' ]))
@@ -271,7 +271,7 @@ class ModifyCheckpointsHandler(APIHandler):
271
271
def post (self , path , checkpoint_id ):
272
272
"""post restores a file from a checkpoint"""
273
273
cm = self .contents_manager
274
- yield gen . maybe_future (cm .restore_checkpoint (checkpoint_id , path ))
274
+ yield maybe_future (cm .restore_checkpoint (checkpoint_id , path ))
275
275
self .set_status (204 )
276
276
self .finish ()
277
277
@@ -280,7 +280,7 @@ def post(self, path, checkpoint_id):
280
280
def delete (self , path , checkpoint_id ):
281
281
"""delete clears a checkpoint for a given file"""
282
282
cm = self .contents_manager
283
- yield gen . maybe_future (cm .delete_checkpoint (checkpoint_id , path ))
283
+ yield maybe_future (cm .delete_checkpoint (checkpoint_id , path ))
284
284
self .set_status (204 )
285
285
self .finish ()
286
286
@@ -307,7 +307,7 @@ class TrustNotebooksHandler(JupyterHandler):
307
307
@gen .coroutine
308
308
def post (self ,path = '' ):
309
309
cm = self .contents_manager
310
- yield gen . maybe_future (cm .trust_notebook (path ))
310
+ yield maybe_future (cm .trust_notebook (path ))
311
311
self .set_status (201 )
312
312
self .finish ()
313
313
#-----------------------------------------------------------------------------
0 commit comments