@@ -131,7 +131,8 @@ def run_post_save_hook(self, model, os_path):
131131 self .post_save_hook (os_path = os_path , model = model , contents_manager = self )
132132 except Exception as e :
133133 self .log .error ("Post-save hook failed o-n %s" , os_path , exc_info = True )
134- raise web .HTTPError (500 , u'Unexpected error while running post hook save: %s' % e )
134+ raise web .HTTPError (500 , u'Unexpected error while running post hook save: %s'
135+ % e ) from e
135136
136137 @validate ('root_dir' )
137138 def _validate_root_dir (self , proposal ):
@@ -241,14 +242,14 @@ def _base_model(self, path):
241242 """Build the common base of a contents model"""
242243 os_path = self ._get_os_path (path )
243244 info = os .lstat (os_path )
244-
245+
245246 try :
246- # size of file
247+ # size of file
247248 size = info .st_size
248249 except (ValueError , OSError ):
249250 self .log .warning ('Unable to get size.' )
250251 size = None
251-
252+
252253 try :
253254 last_modified = tz .utcfromtimestamp (info .st_mtime )
254255 except (ValueError , OSError ):
@@ -390,14 +391,14 @@ def _notebook_model(self, path, content=True):
390391 model = self ._base_model (path )
391392 model ['type' ] = 'notebook'
392393 os_path = self ._get_os_path (path )
393-
394+
394395 if content :
395396 nb = self ._read_notebook (os_path , as_version = 4 )
396397 self .mark_trusted_cells (nb , path )
397398 model ['content' ] = nb
398399 model ['format' ] = 'json'
399400 self .validate_notebook_model (model )
400-
401+
401402 return model
402403
403404 def get (self , path , content = True , type = None , format = None ):
@@ -487,7 +488,8 @@ def save(self, model, path=''):
487488 raise
488489 except Exception as e :
489490 self .log .error (u'Error while saving file: %s %s' , path , e , exc_info = True )
490- raise web .HTTPError (500 , u'Unexpected error while saving file: %s %s' % (path , e ))
491+ raise web .HTTPError (500 , u'Unexpected error while saving file: %s %s' %
492+ (path , e )) from e
491493
492494 validation_message = None
493495 if model ['type' ] == 'notebook' :
@@ -584,7 +586,8 @@ def rename_file(self, old_path, new_path):
584586 except web .HTTPError :
585587 raise
586588 except Exception as e :
587- raise web .HTTPError (500 , u'Unknown error renaming file: %s %s' % (old_path , e ))
589+ raise web .HTTPError (500 , u'Unknown error renaming file: %s %s' %
590+ (old_path , e )) from e
588591
589592 def info_string (self ):
590593 return _ ("Serving notebooks from local directory: %s" ) % self .root_dir
0 commit comments