1010
1111from tornado import gen , web
1212
13- from notebook .utils import url_path_join , url_escape
13+ from notebook .utils import maybe_future , url_path_join , url_escape
1414from jupyter_client .jsonutil import date_default
1515
1616from notebook .base .handlers import (
@@ -108,7 +108,7 @@ def get(self, path=''):
108108 raise web .HTTPError (400 , u'Content %r is invalid' % content )
109109 content = int (content )
110110
111- model = yield gen . maybe_future (self .contents_manager .get (
111+ model = yield maybe_future (self .contents_manager .get (
112112 path = path , type = type , format = format , content = content ,
113113 ))
114114 validate_model (model , expect_content = content )
@@ -122,7 +122,7 @@ def patch(self, path=''):
122122 model = self .get_json_body ()
123123 if model is None :
124124 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 ))
126126 validate_model (model , expect_content = False )
127127 self ._finish_model (model )
128128
@@ -133,7 +133,7 @@ def _copy(self, copy_from, copy_to=None):
133133 copy_from = copy_from ,
134134 copy_to = copy_to or '' ,
135135 ))
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 ))
137137 self .set_status (201 )
138138 validate_model (model , expect_content = False )
139139 self ._finish_model (model )
@@ -142,7 +142,7 @@ def _copy(self, copy_from, copy_to=None):
142142 def _upload (self , model , path ):
143143 """Handle upload of a new file to path"""
144144 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 ))
146146 self .set_status (201 )
147147 validate_model (model , expect_content = False )
148148 self ._finish_model (model )
@@ -151,7 +151,7 @@ def _upload(self, model, path):
151151 def _new_untitled (self , path , type = '' , ext = '' ):
152152 """Create a new, empty untitled entity"""
153153 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 ))
155155 self .set_status (201 )
156156 validate_model (model , expect_content = False )
157157 self ._finish_model (model )
@@ -162,7 +162,7 @@ def _save(self, model, path):
162162 chunk = model .get ("chunk" , None )
163163 if not chunk or chunk == - 1 : # Avoid tedious log information
164164 self .log .info (u"Saving file at %s" , path )
165- model = yield gen . maybe_future (self .contents_manager .save (model , path ))
165+ model = yield maybe_future (self .contents_manager .save (model , path ))
166166 validate_model (model , expect_content = False )
167167 self ._finish_model (model )
168168
@@ -182,11 +182,11 @@ def post(self, path=''):
182182
183183 cm = self .contents_manager
184184
185- file_exists = yield gen . maybe_future (cm .file_exists (path ))
185+ file_exists = yield maybe_future (cm .file_exists (path ))
186186 if file_exists :
187187 raise web .HTTPError (400 , "Cannot POST to files, use PUT instead." )
188188
189- dir_exists = yield gen . maybe_future (cm .dir_exists (path ))
189+ dir_exists = yield maybe_future (cm .dir_exists (path ))
190190 if not dir_exists :
191191 raise web .HTTPError (404 , "No such directory: %s" % path )
192192
@@ -220,21 +220,21 @@ def put(self, path=''):
220220 if model :
221221 if model .get ('copy_from' ):
222222 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 ))
224224 if exists :
225- yield gen . maybe_future (self ._save (model , path ))
225+ yield maybe_future (self ._save (model , path ))
226226 else :
227- yield gen . maybe_future (self ._upload (model , path ))
227+ yield maybe_future (self ._upload (model , path ))
228228 else :
229- yield gen . maybe_future (self ._new_untitled (path ))
229+ yield maybe_future (self ._new_untitled (path ))
230230
231231 @web .authenticated
232232 @gen .coroutine
233233 def delete (self , path = '' ):
234234 """delete a file in the given path"""
235235 cm = self .contents_manager
236236 self .log .warning ('delete %s' , path )
237- yield gen . maybe_future (cm .delete (path ))
237+ yield maybe_future (cm .delete (path ))
238238 self .set_status (204 )
239239 self .finish ()
240240
@@ -246,7 +246,7 @@ class CheckpointsHandler(APIHandler):
246246 def get (self , path = '' ):
247247 """get lists checkpoints for a file"""
248248 cm = self .contents_manager
249- checkpoints = yield gen . maybe_future (cm .list_checkpoints (path ))
249+ checkpoints = yield maybe_future (cm .list_checkpoints (path ))
250250 data = json .dumps (checkpoints , default = date_default )
251251 self .finish (data )
252252
@@ -255,7 +255,7 @@ def get(self, path=''):
255255 def post (self , path = '' ):
256256 """post creates a new checkpoint"""
257257 cm = self .contents_manager
258- checkpoint = yield gen . maybe_future (cm .create_checkpoint (path ))
258+ checkpoint = yield maybe_future (cm .create_checkpoint (path ))
259259 data = json .dumps (checkpoint , default = date_default )
260260 location = url_path_join (self .base_url , 'api/contents' ,
261261 url_escape (path ), 'checkpoints' , url_escape (checkpoint ['id' ]))
@@ -271,7 +271,7 @@ class ModifyCheckpointsHandler(APIHandler):
271271 def post (self , path , checkpoint_id ):
272272 """post restores a file from a checkpoint"""
273273 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 ))
275275 self .set_status (204 )
276276 self .finish ()
277277
@@ -280,7 +280,7 @@ def post(self, path, checkpoint_id):
280280 def delete (self , path , checkpoint_id ):
281281 """delete clears a checkpoint for a given file"""
282282 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 ))
284284 self .set_status (204 )
285285 self .finish ()
286286
@@ -307,7 +307,7 @@ class TrustNotebooksHandler(IPythonHandler):
307307 @gen .coroutine
308308 def post (self ,path = '' ):
309309 cm = self .contents_manager
310- yield gen . maybe_future (cm .trust_notebook (path ))
310+ yield maybe_future (cm .trust_notebook (path ))
311311 self .set_status (201 )
312312 self .finish ()
313313#-----------------------------------------------------------------------------
0 commit comments