ó
§]c           @   sĘ   d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z m Z d d l m Z e j d k  r e Z n e Z d
   Z d   Z d e f d     YZ d S(   s   A preprocessor that extracts all of the outputs from the
notebook file.  The extracted outputs are returned in the 'resources' dictionary.
i˙˙˙˙(   t   dedent(   t
   a2b_base64N(   t   guess_extension(   t   Unicodet   Seti   (   t   Preprocessori   c         C   s%   t  |   } | d k r! d } n  | S(   sŐ   
    This function fixes a problem with '.jpe' extensions
    of jpeg images which are then not recognised by latex.
    For any other case, the function works in the same way
    as mimetypes.guess_extension
    s   .jpes   .jpeg(   R   (   t   mimetypet   ext(    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/extractoutput.pyt   guess_extension_without_jpe   s    	c         C   sI   t  |  t  rE t j d k r3 |  j d d  }  n  |  j d  }  n  |  S(   Nt   win32s   
s   
s   utf-8(   t
   isinstancet	   text_typet   syst   platformt   replacet   encode(   t   data(    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/extractoutput.pyt   platform_utf_8_encode$   s
    t   ExtractOutputPreprocessorc           B   sS   e  Z d  Z e d  j d e  Z e d d d d h  j d e  Z d   Z	 RS(   s   
    Extracts all of the outputs from the notebook file.  The extracted
    outputs are returned in the 'resources' dictionary.
    s,   {unique_key}_{cell_index}_{index}{extension}t   configs	   image/pngs
   image/jpegs   image/svg+xmls   application/pdfc         C   sŁ  | j  d d  } | j  d d  } t | d t  sD i  | d <n  xRt | j  d g    D]8\ } } | j d d h k r q] n  d | j k r˛ t | d d  | d d <n  xŕ|  j D]Ő} | | j k rź | j | }	 | d	 d
 d h k rt	 |	  }	 nq | d k st |	 t
  rgt |	 t  rOt |	 t
  rO|	 j d  }	 n  t t j |	   }	 n t |	  }	 t |  }
 |
 d k rĽd | j d  d }
 n  | j j  d d  rć| j d } | j |
  s| |
 7} qn' |  j j d | d | d | d |
  } | d k	 r1t j j | |  } n  | j j d i   | | j d | <| | d k rt d j | |    n  |	 | d | <qź qź Wq] W| | f S(   s¨  
        Apply a transformation on each cell,

        Parameters
        ----------
        cell : NotebookNode cell
            Notebook cell being processed
        resources : dictionary
            Additional resources used in the conversion process.  Allows
            preprocessors to pass variables into the Jinja engine.
        cell_index : int
            Index of the cell being processed (see base.py)
        t
   unique_keyt   outputt   output_files_dirt   outputst   display_datat   execute_results	   text/htmlR   s	   image/pngs
   image/jpegs   application/pdfs   application/jsons   utf-8t   .t   /i˙˙˙˙t   filenamet    t
   cell_indext   indext	   extensiont	   filenamessO  Your outputs have filename metadata associated with them. Nbconvert saves these outputs to external files using this filename metadata. Filenames need to be unique across the notebook, or images will be overwritten. The filename {} is associated with more than one output. The second output associated with this filename is in cell {}.N(   t   gett   NoneR
   t   dictt	   enumeratet   output_typeR   R    t   extract_output_typesR   R   t   bytest   decodeR   t   jsont   dumpsR   t   rsplitt   metadatat   endswitht   output_filename_templatet   formatt   ost   patht   joint
   setdefaultt
   ValueError(   t   selft   cellt	   resourcesR   R   R   R   t   outt	   mime_typeR   R   R   (    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/extractoutput.pyt   preprocess_cell9   sR    %	(
   t   __name__t
   __module__t   __doc__R   t   tagt   TrueR/   R   R'   R;   (    (    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/extractoutput.pyR   +   s   		(   i   (   R>   t   textwrapR    t   binasciiR   R   R1   R*   t	   mimetypesR   t	   traitletsR   R   t   baseR   t   version_infot
   basestringR   t   strR   R   R   (    (    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/extractoutput.pyt   <module>   s   			