in jupyter-gcs-contents-manager/gcs_contents_manager.py [0:0]
def delete_file(self, path):
if path in ['', '/']:
raise HTTPError(403, 'The top-level directory is read-only')
try:
cm, relative_path, path_prefix = self._content_manager_for_path(path)
if (relative_path in ['', '/']) or (path_prefix in ['', '/']):
raise HTTPError(403, 'The top-level directory contents are read-only')
if not cm:
raise HTTPError(404, 'No content manager defined for "{}"'.format(path))
return cm.delete_file(relative_path)
except OSError as err:
# The built-in file contents manager will not attempt to wrap permissions
# errors when deleting files if they occur while trying to move the
# to-be-deleted file to the trash, because the underlying send2trash
# library does not set the errno attribute of the raised OSError.
#
# To work around this we explicitly catch such errors, check if they
# start with the magic text "Permission denied", and then wrap them
# in an HTTPError.
if str(err).startswith('Permission denied'):
raise HTTPError(403, str(err))
raise HTTPError(
500, 'Internal server error: [{}] {}'.format(err.errno, str(err)))
except HTTPError as err:
raise err
except Exception as ex:
raise HTTPError(
500, 'Internal server error: [{}] {}'.format(type(ex), str(ex)))