B
    3¢\B  ã               @   s4   d dl Z d dlZd dlZd dlZdd„ Zdd„ ZdS )é    Nc               C   s   dddddœgS )z&Metadata for notebook bundlerextensionZtarball_bundlerz notebook.bundler.tarball_bundlerzNotebook Tarball (tar.gz)Zdownload)ÚnameZmodule_nameZlabelÚgroup© r   r   r   ú?lib/python3.7/site-packages/notebook/bundler/tarball_bundler.pyÚ_jupyter_bundlerextension_paths   s    r   c       	   
   C   s´   |d }t  |d ¡ d¡}tj |¡d }d |¡}t |¡}t	|ƒ|_
t ¡ X}tj|d|d}| |t |¡¡ W dQ R X |  |¡ |  d	d
¡ |  | ¡ ¡ W dQ R X dS )a
  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
    r   Zcontentzutf-8r   z	{}.tar.gzzw:gz)ZfileobjNzContent-Typezapplication/gzip)ÚnbformatZwritesÚencodeÚosÚpathÚsplitextÚformatÚtarfileZTarInfoÚlenÚsizeÚioÚBytesIOÚopenZaddfileZset_attachment_headerZ
set_headerZfinishÚgetvalue)	ZhandlerZmodelZnotebook_filenameZnotebook_contentZnotebook_nameZtar_filenameÚinfoZ
tar_bufferZtarr   r   r   Úbundle   s    





r   )r	   r   r   r   r   r   r   r   r   r   Ú<module>   s
   