o
    i                     @   s>   d dl Z d dlZd dlZd dlm  mZ dd Zdd ZdS )    Nc                   C   s   dddddgS )z&Metadata for notebook bundlerextensionnotebook_zip_downloadzIPython Notebook bundle (.zip)znotebook.bundler.zip_bundlerdownload)namelabelmodule_namegroup r   r   r   W/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/bundler/zip_bundler.py_jupyter_bundlerextension_paths   s
   r
   c                 C   s   t j| jd j|d }|d }t j|d }t j|d d }| | | dd t	|d}t
 }tj|d	tjd
}||| t j|}	|D ]}
t j|	|
}|||
 qO|  | |  dS )a  Create a zip file containing the original notebook and files referenced
    from it. Retain the referenced files in paths relative to the notebook.
    Return the zip as a file download. 
    
    Assumes the notebook and other files are all on local disk.
    
    Parameters
    ----------
    handler : tornado.web.RequestHandler
        Handler that serviced the bundle request
    model : dict
        Notebook model from the configured ContentManager
    contents_managerpathr   r   z.zipzContent-Typezapplication/zip   w)modecompressionN)osr   joinsettingsroot_dirsplitextset_attachment_header
set_headertoolsget_file_referencesioBytesIOzipfileZipFileZIP_DEFLATEDwritedirnameclosefinishgetvalue)handlermodelabs_nb_pathnotebook_filenamenotebook_namezip_filenameref_filenames
zip_bufferzipfnotebook_dirnb_relative_filenameabs_fnr   r   r	   bundle   s$   
r0   )r   r   r   notebook.bundler.toolsbundlerr   r
   r0   r   r   r   r	   <module>   s   	