σ
§]c           @@ s  d  Z  d d l m Z m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z m Z d	 e j f d
     YZ d e f d     YZ d e f d     YZ d S(   se   This module defines a base Exporter class. For Jinja template-based export,
see templateexporter.py.
i    (   t   print_functiont   absolute_importN(   t   LoggingConfigurable(   t   Config(   t	   HasTraitst   Unicodet   Listt
   TraitError(   t   import_item(   t   textt	   py3compatt   ResourcesDictc           B@ s   e  Z d    Z RS(   c         C@ s   d S(   Nt    (    (   t   selft   key(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyt   __missing__   s    (   t   __name__t
   __module__R   (    (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR      s   t   FilenameExtensionc           B@ s#   e  Z d  Z d Z d Z d   Z RS(   s    A trait for filename extensions.u    s*   a filename extension, beginning with a dotc         C@ sY   t  t |   j | |  } | rU | j d  rU d } t | j |  j |    n  | S(   Nt   .s8   FileExtension trait '{}' does not begin with a dot: {!r}(   t   superR   t   validatet
   startswithR   t   formatt   name(   R   t   objt   valuet   msg(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR   $   s
    (   R   R   t   __doc__t   default_valuet	   info_textR   (    (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR      s   t   Exporterc           B@ s  e  Z d  Z e d d d j d e  Z d Z d Z	 e
 d d  j d e  Z e
   Z e
 d d d	 d
 d d d d d d d g d d j d e  Z d d  Z e d    Z d d  Z d d  Z d d  Z e d  Z d   Z d   Z d   Z RS(   sΓ   
    Class containing methods that sequentially run a list of preprocessors on a
    NotebookNode object and then return the modified NotebookNode object and
    accompanying resources dict.
    s   .txtt   helps4   Extension of the file that should be written to diskt   configR   s7   List of preprocessors, by name or namespace, to enable.s-   nbconvert.preprocessors.TagRemovePreprocessors/   nbconvert.preprocessors.RegexRemovePreprocessors/   nbconvert.preprocessors.ClearOutputPreprocessors+   nbconvert.preprocessors.ExecutePreprocessors(   nbconvert.preprocessors.coalesce_streamss+   nbconvert.preprocessors.SVG2PDFPreprocessors1   nbconvert.preprocessors.CSSHTMLHeaderPreprocessors)   nbconvert.preprocessors.LatexPreprocessors3   nbconvert.preprocessors.HighlightMagicsPreprocessors1   nbconvert.preprocessors.ExtractOutputPreprocessors1   nbconvert.preprocessors.ClearMetadataPreprocessorsZ   List of preprocessors available by default, by name, namespace,
        instance, or type.c         K@ sI   |  j  } | r | j |  n  t t |   j d | |  |  j   d S(   sϊ   
        Public constructor

        Parameters
        ----------
        config : :class:`~traitlets.config.Config`
            User configuration instance.
        `**kw`
            Additional keyword arguments passed to parent __init__

        R!   N(   t   default_configt   mergeR   R   t   __init__t   _init_preprocessors(   R   R!   t   kwt   with_default_config(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR$   \   s
    	c         C@ s   t    S(   N(   R   (   R   (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR"   q   s    c         K@ sk   t  j |  } |  j |  } d | d k rI | d d j   | d <n  |  j | |  \ } } | | f S(   sn  
        Convert a notebook from a notebook node instance.

        Parameters
        ----------
        nb : :class:`~nbformat.NotebookNode`
          Notebook node (dict-like with attr-access)
        resources : dict
          Additional resources that can be accessed read/write by
          preprocessors and filters.
        `**kw`
          Ignored

        t   languaget   metadata(   t   copyt   deepcopyt   _init_resourcest   lowert   _preprocess(   R   t   nbt	   resourcesR&   t   nb_copy(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyt   from_notebook_nodeu   s    c   	   	   K@ s  t  | t  r! t j |  } n  | d
 k r9 t   } n  d | k sU | d d k re t   | d <n  t j j |  \ } } t j j	 |  d } | | d d <| | d d <t
 j
 j t j j |   } | j t j  | d d <t j | d d  } |  j | d	 | | SWd
 QXd
 S(   s^  
        Convert a notebook from a notebook file.

        Parameters
        ----------
        filename : str
            Full filename of the notebook file to open and convert.
        resources : dict
          Additional resources that can be accessed read/write by
          preprocessors and filters.
        `**kw`
          Ignored

        R)   R   i    R   t   patht   modified_datet   encodings   utf-8R0   N(   t
   isinstancet   strR
   t   str_to_unicodet   NoneR   t   osR3   t   splitt   splitextt   datetimet   fromtimestampt   getmtimet   strftimeR	   t   date_formatt   iot   opent	   from_file(	   R   t   filenameR0   R&   R3   t   basenamet   notebook_nameR4   t   f(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyt   from_filename   s    c         K@ s%   |  j  t j | d d d | | S(   s\  
        Convert a notebook from a notebook file.

        Parameters
        ----------
        file_stream : file-like object
            Notebook file-like object to convert.
        resources : dict
          Additional resources that can be accessed read/write by
          preprocessors and filters.
        `**kw`
          Ignored

        t
   as_versioni   R0   (   R2   t   nbformatt   read(   R   t   file_streamR0   R&   (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyRD   Ά   s    c         C@ s  | d k r t d   n  t | t  } | } | re t | t j  re t |  } |  j | |  S| r  t | d  r  | r t	 | _
 n  |  j j |  | S| rΡ t | t  rΡ |  j | d |   |  n, | rν |  j |   |  n t d |   d S(   s  
        Register a preprocessor.
        Preprocessors are classes that act upon the notebook before it is
        passed into the Jinja templating engine.  preprocessors are also
        capable of passing additional information to the Jinja
        templating engine.

        Parameters
        ----------
        preprocessor : :class:`~nbconvert.preprocessors.Preprocessor`
            A dotted module name, a type, or an instance
        enabled : bool
            Mark the preprocessor as enabled

        s   preprocessor must not be Nonet   __call__t   parentsB   preprocessor must be callable or an importable constructor, got %rN(   R9   t	   TypeErrorR6   t   typeR
   t   string_typesR   t   register_preprocessort   hasattrt   Truet   enabledt   _preprocessorst   appendt
   issubclassR   (   R   t   preprocessorRV   t   isclasst   constructedt   preprocessor_cls(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyRS   Θ   s"    c         C@ sU   g  |  _  x |  j D] } |  j |  q Wx$ |  j D] } |  j | d t q4 Wd S(   s{   
        Register all of the preprocessors needed for this exporter, disabled
        unless specified explicitly.
        RV   N(   RW   t   default_preprocessorsRS   t   preprocessorsRU   (   R   RZ   (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR%   ϋ   s
    	c         C@ sΜ   | d  k r t   } n  t | t  sF t   } | j |  | } n  d | k r t | d t  s» t   } | j | d  | | d <q» n, t   | d <| d d s» d | d d <n  |  j | d <| S(   NR)   R   t   Notebookt   output_extension(   R9   R   R6   t   updatet   file_extension(   R   R0   t   new_resourcest   new_metadata(    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR,     s     			c         C@ s   t  j |  } t  j |  } xj |  j D]_ } | | |  \ } } y t j | d t Wq( t j k
 r |  j j d |    q( Xq( W| | f S(   sΫ  
        Preprocess the notebook before passing it into the Jinja engine.
        To preprocess the notebook is to successively apply all the
        enabled preprocessors. Output from each preprocessor is passed
        along to the next one.

        Parameters
        ----------
        nb : notebook node
            notebook that is being exported.
        resources : a dict of additional resources that
            can be accessed read/write by preprocessors
        t   relax_add_propss)   Notebook is invalid after preprocessor {}(	   R*   R+   RW   RK   R   RU   t   ValidationErrort   logt   error(   R   R/   R0   t   nbct   rescRZ   (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR.   %  s    N(   R   R   R   R   t   tagRU   Rc   t   output_mimetypeR9   t   export_from_notebookR   R_   RW   R^   R$   t   propertyR"   R2   RI   RD   t   FalseRS   R%   R,   R.   (    (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyR   0   sB   						&3		(   R   t
   __future__R    R   RB   R:   R*   t   collectionsR=   RK   t   traitlets.config.configurableR   t   traitlets.configR   t	   traitletsR   R   R   R   t   traitlets.utils.importstringR   t   ipython_genutilsR	   R
   t   defaultdictR   R   R   (    (    (    s;   lib/python2.7/site-packages/nbconvert/exporters/exporter.pyt   <module>   s   "