Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
47
venv/Lib/site-packages/notebook/bundler/tarball_bundler.py
Normal file
47
venv/Lib/site-packages/notebook/bundler/tarball_bundler.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
import os
|
||||
import io
|
||||
import tarfile
|
||||
import nbformat
|
||||
|
||||
def _jupyter_bundlerextension_paths():
|
||||
"""Metadata for notebook bundlerextension"""
|
||||
return [{
|
||||
# unique bundler name
|
||||
"name": "tarball_bundler",
|
||||
# module containing bundle function
|
||||
"module_name": "notebook.bundler.tarball_bundler",
|
||||
# human-readable menu item label
|
||||
"label" : "Notebook Tarball (tar.gz)",
|
||||
# group under 'deploy' or 'download' menu
|
||||
"group" : "download",
|
||||
}]
|
||||
|
||||
def bundle(handler, model):
|
||||
"""Create a compressed tarball containing the notebook document.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
handler : tornado.web.RequestHandler
|
||||
Handler that serviced the bundle request
|
||||
model : dict
|
||||
Notebook model from the configured ContentManager
|
||||
"""
|
||||
notebook_filename = model['name']
|
||||
notebook_content = nbformat.writes(model['content']).encode('utf-8')
|
||||
notebook_name = os.path.splitext(notebook_filename)[0]
|
||||
tar_filename = '{}.tar.gz'.format(notebook_name)
|
||||
|
||||
info = tarfile.TarInfo(notebook_filename)
|
||||
info.size = len(notebook_content)
|
||||
|
||||
with io.BytesIO() as tar_buffer:
|
||||
with tarfile.open(tar_filename, "w:gz", fileobj=tar_buffer) as tar:
|
||||
tar.addfile(info, io.BytesIO(notebook_content))
|
||||
|
||||
handler.set_attachment_header(tar_filename)
|
||||
handler.set_header('Content-Type', 'application/gzip')
|
||||
|
||||
# Return the buffer value as the response
|
||||
handler.finish(tar_buffer.getvalue())
|
||||
Loading…
Add table
Add a link
Reference in a new issue