environment/lib/python2.7/site-packages/IPython/frontend/html/notebook/notebookmanager.py
def save_notebook_object(self, notebook_id, nb):
        """Save an existing notebook object by notebook_id."""
        if notebook_id not in self.mapping:
            raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
        old_name = self.mapping[notebook_id]
        try:
            new_name = nb.metadata.name
        except AttributeError:
            raise web.HTTPError(400, u'Missing notebook name')
        path = self.get_path_by_name(new_name)
        try:
            with open(path,'w') as f:
                current.write(nb, f, u'json')
        except Exception as e:
            raise web.HTTPError(400, u'Unexpected error while saving notebook: %s' % e)
        # save .py script as well
        if self.save_script:
            pypath = os.path.splitext(path)[0] + '.py'
            try:
                with io.open(pypath,'w', encoding='utf-8') as f:
                    current.write(nb, f, u'py')
            except Exception as e:
                raise web.HTTPError(400, u'Unexpected error while saving notebook as script: %s' % e)
        
        if old_name != new_name:
            old_path = self.get_path_by_name(old_name)
            if os.path.isfile(old_path):
                os.unlink(old_path)
            if self.save_script:
                old_pypath = os.path.splitext(old_path)[0] + '.py'
                if os.path.isfile(old_pypath):
                    os.unlink(old_pypath)
            self.mapping[notebook_id] = new_name
            self.rev_mapping[new_name] = notebook_id
            del self.rev_mapping[old_name]
def save_notebook_object(self, notebook_id, nb):
        if notebook_id not in self.mapping:
            raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
        old_name = self.mapping[notebook_id]
        try:
            new_name = nb.metadata.name
        except AttributeError:
            raise web.HTTPError(400, u'Missing notebook name')
        path = self.get_path_by_name(new_name)
        try:
            with open(path,'w') as f:
                current.write(nb, f, u'json')
        except Exception as e:
            raise web.HTTPError(400, u'Unexpected error while saving notebook: %s' % e)
        # save .py script as well
        if self.save_script:
            pypath = os.path.splitext(path)[0] + '.py'
            try:
                with io.open(pypath,'w', encoding='utf-8') as f:
                    current.write(nb, f, u'py')
            except Exception as e:
                raise web.HTTPError(400, u'Unexpected error while saving notebook as script: %s' % e)
        
        if old_name != new_name:
            old_path = self.get_path_by_name(old_name)
            if os.path.isfile(old_path):
                os.unlink(old_path)
            if self.save_script:
                old_pypath = os.path.splitext(old_path)[0] + '.py'
                if os.path.isfile(old_pypath):
                    os.unlink(old_pypath)
            self.mapping[notebook_id] = new_name
            self.rev_mapping[new_name] = notebook_id
            del self.rev_mapping[old_name]
def save_notebook_object ( self , notebook_id , nb ) : if notebook_id not in self . mapping : raise web . HTTPError ( 404 , u'Notebook does not exist: %s' % notebook_id ) old_name = self . mapping [ notebook_id ] try : new_name = nb . metadata . name except AttributeError : raise web . HTTPError ( 400 , u'Missing notebook name' ) path = self . get_path_by_name ( new_name ) try : with open ( path , 'w' ) as f : current . write ( nb , f , u'json' ) except Exception as e : raise web . HTTPError ( 400 , u'Unexpected error while saving notebook: %s' % e ) # save .py script as well if self . save_script : pypath = os . path . splitext ( path ) [ 0 ] + '.py' try : with io . open ( pypath , 'w' , encoding = 'utf-8' ) as f : current . write ( nb , f , u'py' ) except Exception as e : raise web . HTTPError ( 400 , u'Unexpected error while saving notebook as script: %s' % e ) if old_name != new_name : old_path = self . get_path_by_name ( old_name ) if os . path . isfile ( old_path ) : os . unlink ( old_path ) if self . save_script : old_pypath = os . path . splitext ( old_path ) [ 0 ] + '.py' if os . path . isfile ( old_pypath ) : os . unlink ( old_pypath ) self . mapping [ notebook_id ] = new_name self . rev_mapping [ new_name ] = notebook_id del self . rev_mapping [ old_name ]
Save an existing notebook object by notebook_id.
Save an existing notebook object by notebook_id .