ó
ù2¢\c           @   sL   d  d l  Z  d  d l Z d  d l Z d  d l j j Z d „  Z d „  Z d S(   iÿÿÿÿNc           C   s#   i d d 6d d 6d d 6d d 6g S(	   s&   Metadata for notebook bundlerextensiont   notebook_zip_downloadt   names   IPython Notebook bundle (.zip)t   labels   notebook.bundler.zip_bundlert   module_namet   downloadt   group(    (    (    (    s;   lib/python2.7/site-packages/notebook/bundler/zip_bundler.pyt   _jupyter_bundlerextension_paths   s
    c         C   s/  t  j j |  j d j | d ƒ } | d } t  j j | ƒ d } t  j j | ƒ d d } |  j | ƒ |  j d d ƒ t j	 | d ƒ } t
 j ƒ  } t j | d	 d
 d t j ƒ} | j | | ƒ t  j j | ƒ }	 x3 | D]+ }
 t  j j |	 |
 ƒ } | j | |
 ƒ qß W| j ƒ  |  j | j ƒ  ƒ d S(   sÍ  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
    t   contents_managert   pathR   i    s   .zips   Content-Types   application/zipi   t   modet   wt   compressionN(   t   osR   t   joint   settingst   root_dirt   splitextt   set_attachment_headert
   set_headert   toolst   get_file_referencest   iot   BytesIOt   zipfilet   ZipFilet   ZIP_DEFLATEDt   writet   dirnamet   closet   finisht   getvalue(   t   handlert   modelt   abs_nb_patht   notebook_filenamet   notebook_namet   zip_filenamet   ref_filenamest
   zip_buffert   zipft   notebook_dirt   nb_relative_filenamet   abs_fn(    (    s;   lib/python2.7/site-packages/notebook/bundler/zip_bundler.pyt   bundle   s"    

(   R   R   R   t   notebook.bundler.toolst   bundlerR   R   R+   (    (    (    s;   lib/python2.7/site-packages/notebook/bundler/zip_bundler.pyt   <module>   s
   		